打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
将pc中的文件夹从一个目录拷贝到另外的一个目录
userphoto

2013.01.31

关注
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
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
CFileFind用法小结
VC文件目录常见操作
[转载]VC中判断目录,文件是否存在,创建目录,求目录或
隐藏文件四大妙招
mysql通过拷贝data目录恢复数据
删除文件夹以及文件夹下的所有文件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服