c++ api MoveFile的问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 04:58:08
c++ api移动文件MoveFile怎么用
比如说要从d盘下移动一个文件到c盘的X文件夹下

The MoveFile function will move (rename) either a file or a directory (including its children) either in the same directory or across directories. The one caveat is that the MoveFile function will fail on directory moves when the destination is on a different volume.

你需要先Copy然后再删除原来的。

直接Move可以从D到C盘根目录,如果有子目录的话就需要用特殊的方法来处理。

下面这个是对的:
#include <windows.h>

#include <tchar.h>

int _tmain()
{
if( 0 == MoveFile( _T("D:\\1.txt"), _T("C:\\w.txt") ) )
{
::MessageBox( NULL, _T("移动失败"), _T("错误"), 0 );

return 0;
}

return 0;
}

下面这个是错的:
#include <windows.h>

#include <tchar.h>

int _tmain()
{
if( 0 == MoveFile( _T("D:\\1.txt"), _T("C:\\dd\\w.txt") ) )
{
::MessageBox( NULL, _T("移动失败"), _T