1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// 将pc中的文件夹从一个目录拷贝到另外的一个目录
BOOL CopyDirectory(CString strSrcPath, CString strDesPath, BOOL bFailIfExists/*=FALSE*/)
{
if( strSrcPath.IsEmpty() )
{
OutputDebugString("源文件名为空,无法进行拷贝!");
return FALSE;
}
if ( !DirectoryExist(strDesPath) )
{
if ( !PCNewFileCopy( strDesPath ) )
return FALSE;
}
if ( strSrcPath.GetAt(strSrcPath.GetLength()-1) != '\\' )
strSrcPath += '\\';
if ( strDesPath.GetAt(strDesPath.GetLength()-1) != '\\' )
strDesPath += '\\';
BOOL bRet = FALSE; // 因为源目录不可能为空,所以该值一定会被修改
CFileFind ff;
BOOL bFound = ff.FindFile(strSrcPath+"*", 0);
while(bFound) // 递归拷贝
{
bFound = ff.FindNextFile();
if( ff.GetFileName() == "." || ff.GetFileName() == ".." )
continue;
CString strSubSrcPath = ff.GetFilePath();
CString strSubDespath = strSubSrcPath;
strSubDespath.Replace(strSrcPath, strDesPath);
if( ff.IsDirectory() )
bRet = CopyDirectory(strSubSrcPath, strSubDespath, bFailIfExists); // 递归拷贝文件夹
else
bRet = CopyFile(strSubSrcPath, strSubDespath, bFailIfExists); // 拷贝文件
if ( !bRet )
break;
}
ff.Close();
return bRet;
}
用CopyFile肯定不行,还是自己ReadFile,WriteFile这样才能实现进度条。
FindFirstFile FindNextFile FindClose
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。