📄 move.c
字号:
/* Get the file name */
memset(&findBuffer,0,sizeof(WIN32_FIND_DATAW));
hFile = FindFirstFileW(lpExistingFileName2, &findBuffer);
if (hFile == NULL)
loop=FALSE;
if (findBuffer.cFileName[0] == L'\0')
loop=FALSE;
/* FIXME
* remove readonly flag from source folder and do not set the readonly flag to dest folder
*/
RemoveReadOnlyAttributeW(lpExistingFileName);
RemoveReadOnlyAttributeW(lpNewFileName);
//CreateDirectoryExW(lpExistingFileName,lpNewFileName,NULL);
CreateDirectoryW(lpNewFileName, NULL);
/* search the files/folders and move them */
while (loop==TRUE)
{
Result = TRUE;
if ((!wcscmp(findBuffer.cFileName,L"..")) || (!wcscmp(findBuffer.cFileName,L".")))
{
loop = FindNextFileW(hFile, &findBuffer);
if (!loop)
{
size = wcslen(lpExistingFileName2)-4;
FindClose(hFile);
wcscpy( &lpExistingFileName2[size],L"\0");
if (wcsncmp(lpExistingFileName,lpExistingFileName2,size))
{
DWORD Attributes;
FindClose(hFile);
/* delete folder */
DPRINT("MoveFileWithProgressW : Delete folder : %S\n",lpDeleteFile);
/* remove system folder flag other wise we can not delete the folder */
Attributes = GetFileAttributesW(lpExistingFileName2);
if (Attributes != INVALID_FILE_ATTRIBUTES)
{
SetFileAttributesW(lpExistingFileName2,(Attributes & ~FILE_ATTRIBUTE_SYSTEM));
}
RemoveReadOnlyAttributeW(lpExistingFileName2);
Result = RemoveDirectoryW(lpExistingFileName2);
if (Result == FALSE)
break;
loop=TRUE;
size = wcslen(lpExistingFileName);
if (size+6>max_size)
{
if (lpNewFileName2 != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
if (lpExistingFileName2 != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpExistingFileName2);
if (lpDeleteFile != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
return FALSE;
}
wcscpy( lpExistingFileName2,lpExistingFileName);
wcscpy( &lpExistingFileName2[size],L"\\*.*\0");
/* Get the file name */
memset(&findBuffer,0,sizeof(WIN32_FIND_DATAW));
hFile = FindFirstFileW(lpExistingFileName2, &findBuffer);
}
}
continue;
}
if (findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
/* Build the new src string */
size = wcslen(findBuffer.cFileName);
size2= wcslen(lpExistingFileName2);
if (size2+size+6>max_size)
{
FindClose(hFile);
if (lpNewFileName2 != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
if (lpExistingFileName2 != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpExistingFileName2);
if (lpDeleteFile != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
return FALSE;
}
wcscpy( &lpExistingFileName2[size2-3],findBuffer.cFileName);
wcscpy( &lpExistingFileName2[size2+size-3],L"\0");
/* Continue */
wcscpy( lpDeleteFile,lpExistingFileName2);
wcscpy( &lpExistingFileName2[size2+size-3],L"\\*.*\0");
/* Build the new dst string */
size = wcslen(lpExistingFileName2) + wcslen(lpNewFileName);
size2 = wcslen(lpExistingFileName);
if (size>max_size)
{
FindClose(hFile);
if (lpNewFileName2 != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
if (lpExistingFileName2 != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpExistingFileName2);
if (lpDeleteFile != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
return FALSE;
}
wcscpy( lpNewFileName2,lpNewFileName);
size = wcslen(lpNewFileName);
wcscpy( &lpNewFileName2[size], &lpExistingFileName2[size2]);
size = wcslen(lpNewFileName2);
wcscpy( &lpNewFileName2[size-4],L"\0");
/* Create Folder */
/* FIXME
* remove readonly flag from source folder and do not set the readonly flag to dest folder
*/
RemoveReadOnlyAttributeW(lpDeleteFile);
RemoveReadOnlyAttributeW(lpNewFileName2);
CreateDirectoryW(lpNewFileName2,NULL);
//CreateDirectoryExW(lpDeleteFile, lpNewFileName2,NULL);
/* set new search path from src string */
FindClose(hFile);
memset(&findBuffer,0,sizeof(WIN32_FIND_DATAW));
hFile = FindFirstFileW(lpExistingFileName2, &findBuffer);
}
else
{
/* Build the new string */
size = wcslen(findBuffer.cFileName);
size2= wcslen(lpExistingFileName2);
wcscpy( lpDeleteFile,lpExistingFileName2);
wcscpy( &lpDeleteFile[size2-3],findBuffer.cFileName);
/* Build dest string */
size = wcslen(lpDeleteFile) + wcslen(lpNewFileName);
size2 = wcslen(lpExistingFileName);
if (size>max_size)
{
FindClose(hFile);
if (lpNewFileName2 != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
if (lpExistingFileName2 != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpExistingFileName2);
if (lpDeleteFile != NULL)
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
return FALSE;
}
wcscpy( lpNewFileName2,lpNewFileName);
size = wcslen(lpNewFileName);
wcscpy(&lpNewFileName2[size],&lpDeleteFile[size2]);
/* overrite existsen file, if the file got the flag have readonly
* we need reomve that flag
*/
/* copy file */
DPRINT("MoveFileWithProgressW : Copy file : %S to %S\n",lpDeleteFile, lpNewFileName2);
RemoveReadOnlyAttributeW(lpDeleteFile);
RemoveReadOnlyAttributeW(lpNewFileName2);
Result = CopyFileExW (lpDeleteFile,
lpNewFileName2,
lpProgressRoutine,
lpData,
NULL,
0);
if (Result == FALSE)
break;
/* delete file */
DPRINT("MoveFileWithProgressW : remove readonly flag from file : %S\n",lpNewFileName2);
Result = RemoveReadOnlyAttributeW(lpDeleteFile);
if (Result == FALSE)
break;
DPRINT("MoveFileWithProgressW : Delete file : %S\n",lpDeleteFile);
Result = DeleteFileW(lpDeleteFile);
if (Result == FALSE)
break;
}
loop = FindNextFileW(hFile, &findBuffer);
}
/* Remove last folder */
if ((loop == FALSE) && (Result != FALSE))
{
DWORD Attributes;
Attributes = GetFileAttributesW(lpDeleteFile);
if (Attributes != INVALID_FILE_ATTRIBUTES)
{
SetFileAttributesW(lpDeleteFile,(Attributes & ~FILE_ATTRIBUTE_SYSTEM));
}
Result = RemoveDirectoryW(lpExistingFileName);
}
/* Cleanup */
FindClose(hFile);
if (lpNewFileName2 != NULL)
{
HeapFree(GetProcessHeap(),0,(VOID *) lpNewFileName2);
lpNewFileName2 = NULL;
}
if (lpExistingFileName2 != NULL)
{
HeapFree(GetProcessHeap(),0,(VOID *) lpExistingFileName2);
lpExistingFileName2 = NULL;
}
if (lpDeleteFile != NULL)
{
HeapFree(GetProcessHeap(),0,(VOID *) lpDeleteFile);
lpDeleteFile = NULL;
}
return Result;
// end move folder code
}
}
return Result;
}
/*
* @implemented
*/
BOOL
STDCALL
MoveFileWithProgressA (
LPCSTR lpExistingFileName,
LPCSTR lpNewFileName,
LPPROGRESS_ROUTINE lpProgressRoutine,
LPVOID lpData,
DWORD dwFlags
)
{
PWCHAR ExistingFileNameW;
PWCHAR NewFileNameW;
BOOL ret;
if (!(ExistingFileNameW = FilenameA2W(lpExistingFileName, FALSE)))
return FALSE;
if (!(NewFileNameW= FilenameA2W(lpNewFileName, TRUE)))
return FALSE;
ret = MoveFileWithProgressW (ExistingFileNameW ,
NewFileNameW,
lpProgressRoutine,
lpData,
dwFlags);
RtlFreeHeap (RtlGetProcessHeap (), 0, NewFileNameW);
return ret;
}
/*
* @implemented
*/
BOOL
STDCALL
MoveFileW (
LPCWSTR lpExistingFileName,
LPCWSTR lpNewFileName
)
{
return MoveFileExW (lpExistingFileName,
lpNewFileName,
MOVEFILE_COPY_ALLOWED);
}
/*
* @implemented
*/
BOOL
STDCALL
MoveFileExW (
LPCWSTR lpExistingFileName,
LPCWSTR lpNewFileName,
DWORD dwFlags
)
{
return MoveFileWithProgressW (lpExistingFileName,
lpNewFileName,
NULL,
NULL,
dwFlags);
}
/*
* @implemented
*/
BOOL
STDCALL
MoveFileA (
LPCSTR lpExistingFileName,
LPCSTR lpNewFileName
)
{
return MoveFileExA (lpExistingFileName,
lpNewFileName,
MOVEFILE_COPY_ALLOWED);
}
/*
* @implemented
*/
BOOL
STDCALL
MoveFileExA (
LPCSTR lpExistingFileName,
LPCSTR lpNewFileName,
DWORD dwFlags
)
{
return MoveFileWithProgressA (lpExistingFileName,
lpNewFileName,
NULL,
NULL,
dwFlags);
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -