(
1)将已有文件夹中的文件拷贝至另一个文件夹,实现方法如下所示:
BOOL CopyDirectory(CString strTargetDir, CString strSourceDir,
BOOL bFilterDotName)
{
if(strTargetDir
.IsEmpty() || strSourceDir
.IsEmpty())
{
return FALSE;
}
if (PathFileExists(strSourceDir))
{
if (PathFileExists(strTargetDir))
{
DeleteFiles(strTargetDir+_T(
'\0'));
}
CreateDirectoryOfAll(strTargetDir);
CString strDisk = strTargetDir
.Left(
2);
UINT64 nDiskFreeSize = GetDiskFreeSpace(strDisk);
UINT64 nFolderSize =
0;
GetFolderContainerSize(strSourceDir, nFolderSize);
if(nDiskFreeSize - DISK_REMAIN_CONST < nFolderSize)
{
PRDEMessageBox(ERPDE_HDD_FULL, MB_OK|MB_ICONERROR,
NULL, EPRDE_MSGBOX_TITLE_ERROR);
return FALSE;
}
CFileFind fFinder;
CString strDirExe = strSourceDir + _T(
"\\*.*");
BOOL bFind = fFinder
.FindFile(strDirExe);
while(bFind)
{
bFind = fFinder
.FindNextFile();
CString strName = fFinder
.GetFileName();
strDirExe = strTargetDir + _T(
"\\") + fFinder
.GetFileName();
if(fFinder
.IsDots())
{
continue;
}
if (bFilterDotName && strName
.GetAt(
0)==
'.')
{
continue;
}
else if(fFinder
.IsDirectory())
{
CreateDirectory(strDirExe,
NULL);
CopyDirectory(strDirExe, fFinder
.GetFilePath(), bFilterDotName);
}
else
{
CopyFile(fFinder
.GetFilePath(), strDirExe,
FALSE);
}
if(!bFind)
{
break;
}
}
fFinder
.Close();
}
return TRUE;
}
(
2)对文件的路径移动操作,其方法实现:
BOOL MoveDirectory(CString strTargetDir, CString strSourceDir,
int* pnFileCnt)
{
if (strTargetDir == strSourceDir)
{
*pnFileCnt =
0;
return TRUE;
}
if(strTargetDir
.IsEmpty() || strSourceDir
.IsEmpty())
{
return FALSE;
}
if (PathFileExists(strTargetDir))
{
DeleteFiles(strTargetDir+_T(
'\0'));
}
CString strDisk = strTargetDir
.Left(
2);
CString strsorDisk = strSourceDir
.Left(
2);
strDisk
.MakeUpper();
strsorDisk
.MakeUpper();
if(strDisk
.Compare(strsorDisk) !=
0)
{
UINT64 nDiskFreeSize = GetDiskFreeSpace(strDisk);
UINT64 nFolderSize =
0;
GetFolderContainerSize(strSourceDir, nFolderSize);
if(nDiskFreeSize - DISK_REMAIN_CONST < nFolderSize)
{
PRDE_BROADCAST_MESSAGE(WM_PRDE_MOVE_DIRECTORY_DISK_FULL,
0,
0);
return FALSE;
}
}
CreateDirectoryOfAll(strTargetDir);
CFileFind fFinder;
CString strDirExe = strSourceDir + _T(
"\\*.*");
BOOL bFind = fFinder
.FindFile(strDirExe);
while(bFind)
{
bFind = fFinder
.FindNextFile();
strDirExe = strTargetDir + _T(
"\\") + fFinder
.GetFileName();
if(fFinder
.IsDots())
{
continue;
}
else if(fFinder
.IsDirectory())
{
CreateDirectory(strDirExe,
NULL);
if(!MoveDirectory(strDirExe, fFinder
.GetFilePath(), pnFileCnt))
{
fFinder
.Close();
return FALSE;
}
}
else
{
BOOL bRet = MoveFileEx(fFinder
.GetFilePath(), strDirExe, MOVEFILE_COPY_ALLOWED|MOVEFILE_WRITE_THROUGH);
ASSERT(bRet);
if(bRet)
{
if (pnFileCnt)
(*pnFileCnt)++;
}
else
{
Error(SIV_LOG_EDITOR_PRODUCTIONMOD_MAROC,_T(
"$$[MoveFileEx] Failed File Path = %s\n"),fFinder
.GetFilePath());
bRet = CopyFile(fFinder
.GetFilePath(), strDirExe,
FALSE);
ASSERT(bRet);
if(bRet)
{
Debug(SIV_LOG_EDITOR_PRODUCTIONMOD_MAROC,_T(
"$$[CopyFile] Succussed File Path = %s\n"),fFinder
.GetFilePath());
if (pnFileCnt)
(*pnFileCnt)++;
}
else
{
fFinder
.Close();
return FALSE;
}
}
DeleteFile(fFinder
.GetFilePath());
}
if(!bFind)
{
break;
}
}
fFinder
.Close();
return TRUE;
}
转载请注明原文地址: https://ju.6miu.com/read-963705.html