VC如何实现对整个目录的拷贝

abc 2000-02-21 10:54:00
...全文
772 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dann 2000-02-26
  • 打赏
  • 举报
回复
VOID CopyDirectory( LPCSTR lpsrcPath, LPCSTR lpdstPath )
{
SHFILEOPSTRUCT FileOp;

FileOp.hwnd = NULL;
FileOp.wFunc = FO_COPY;
FileOp.pFrom = lpsrcPath;
FileOp.pTo = lpdstPath;
FileOp.fFlags = FOF_NOCONFIRMATION and FOF_NOCONFIRMMKDIR and FOF_NOERRORUI and FOF_SILENT;
FileOp.hNameMappings = NULL;
FileOp.lpszProgressTitle = NULL;

SHFileOperation( &FileOp );
}

CopyDirectory( "C:\dir1", "D:\dir2" );

如果不存在D:\dir2,则C:\dir1中的内容被拷贝到D:\dir2,但如果已经存在了D:\dir2,则C:\dir1中的内容被拷贝到D:\dir2\dir1中。
fupf88 2000-02-26
  • 打赏
  • 举报
回复
还在讨论啊.我作过一个删除整个目录的程序,肯定可以通过的,供ab朋友参考吧:
CFileFind finder;

char string[70];
string[0]='\0';
strcpy(string,PM_TEMP);
strcat(string,"*.*");
BOOL bWorking = finder.FindFile(string);
while (bWorking)
{
bWorking = finder.FindNextFile();
strcpy(string,(LPCTSTR)finder.GetFilePath());
if(::DeleteFile(string)==FALSE&&(string[strlen(string)-1]!='.'))
{
AfxMessageBox("不能删除指定的文件!");
break;
}
}
换成CopyFile()大概可以吧
michel 2000-02-24
  • 打赏
  • 举报
回复
SHFILEOPSTRUCT fileOp;
memset(&fileOp, 0, sizeof(fileOp));
fileOp.wFunc=FO_COPY;
fileOp.fFlags=FOF_NOCONFIRMATION;
fileOp.pFrom=某个目录\*.*, 后面加'\0'
fileOp.pTo=要拷贝的目录;
if (0==::SHFileOperation(&fileOp))
//Success
else
//failure
DragonCheng 2000-02-23
  • 打赏
  • 举报
回复
你如果不想用WInexec()或System()函数,那你可以用CComboBox控件,其成员函数Dir()可以帮你找出目录下的所有文件,然后用CopyFile()函数实现拷贝
qiujoe 2000-02-22
  • 打赏
  • 举报
回复
WINSHELLAPI int WINAPI SHFileOperation( LPSHFILEOPSTRUCT lpFileOp );
lpFileOp: SHFILEOPSTRUCT 结构的地址
结构的具体内容可查阅MSDN
abc 2000-02-22
  • 打赏
  • 举报
回复
SHFileOperation的用法?
fupf88 2000-02-22
  • 打赏
  • 举报
回复
blaise,you can try System("copy c:\ d:\/s/e") too,Ha...
Fancy 2000-02-22
  • 打赏
  • 举报
回复
longx說得很對!
longx 2000-02-22
  • 打赏
  • 举报
回复
简单的方法是调用Shell函数SHFileOperation.就可轻松搞定.
blaise 2000-02-22
  • 打赏
  • 举报
回复
why not winexec("copy c:\ d:\/s/e")?
blaise 2000-02-21
  • 打赏
  • 举报
回复
#define _WIN32_WINNT 0x0400

#include "windows.h"
void copydir(char* src,char* dst)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
char tmpsrc[256];
strcpy(tmpsrc,src);
strcat(tmpsrc,"\\*.*");
hFind = FindFirstFile(tmpsrc, &FindFileData);
if(hFind == INVALID_HANDLE_VALUE)
return;
CreateDirectory(dst,0);
do
{
char newdst[256];
strcpy(newdst,dst);
if(newdst[strlen(newdst)]!='\\')
strcat(newdst,"\\");
strcat(newdst,FindFileData.cFileName);


char newsrc[256];
strcpy(newsrc,src);
if(newsrc[strlen(newsrc)]!='\\')
strcat(newsrc,"\\");
strcat(newsrc,FindFileData.cFileName);
if(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
if(strcmp(FindFileData.cFileName,".")!=0&&strcmp(FindFileData.cFileName,"..")!=0)
{
copydir(newsrc,newdst);
}
}else
{
CopyFile(newsrc,newdst,false);
}
}while(FindNextFile(hFind,&FindFileData));
FindClose(hFind);
}
int
main(int argc, char *argv[])
{
copydir("C:\\gstools","d:\\ggg");

return (0);
}

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧