ディレクトリの移動
ディレクトリを別の場所に移動し、その中に含まれるファイルとサブディレクトリに移動するには、 MoveFileEx、 MoveFileWithProgress、または MoveFileTransacted 関数を呼び出します。 MoveFileWithProgress 関数の機能は MoveFileEx と同じですが、MoveFileWithProgress を使用すると、操作の進行状況に関する通知を受け取るコールバック ルーチンを指定できます。 MoveFileTransacted 関数を使用すると、操作をトランザクション操作として実行できます。
次の例では、ディレクトリで MoveFileEx 関数を使用する方法を示します。
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int __cdecl _tmain(int argc, TCHAR *argv[])
{
printf("\n");
if( argc != 3 )
{
printf("ERROR: Incorrect number of arguments\n\n");
printf("Description:\n");
printf(" Moves a directory and its contents\n\n");
printf("Usage:\n");
_tprintf(TEXT(" %s [source_dir] [target_dir]\n\n"), argv[0]);
printf(" The target directory cannot exist already.\n\n");
return;
}
// Move the source directory to the target directory location.
// The target directory must be on the same drive as the source.
// The target directory cannot already exist.
if (!MoveFileEx(argv[1], argv[2], MOVEFILE_WRITE_THROUGH))
{
printf ("MoveFileEx failed with error %d\n", GetLastError());
return;
}
else _tprintf(TEXT("%s has been moved to %s\n"), argv[1], argv[2]);
}