CopyFile函数如何拷贝某一目录的所有文件 如 *.* 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你要先遍历这个目录下的所有文件,CopyFile函数本身不能拷贝某一目录的所有文件。 FindFirstFileFindNextFile...如果是MFC的话直接用CFileFind... 使用CFileFind类遍历所有的文件,取出各个文件名,再循环拷贝即可。 you can try SHFileOperation with flag FO_COPY char Sou[_MAX_PATH];char Des[_MAX_PATH];SHFILEOPSTRUCT sfo;memset(Sou, 0, sizeof(Sou));strcpy(Sou, "C:\\Dir1");strcpy(Des, "C:\\Dir2"); //目录必须存在memset(&sfo, 0, sizeof(sfo));sfo.wFunc = FO_COPY;sfo.pFrom = Sou;sfo.pTo = Des;SHFileOperation(&sfo);注意,sfo.pFrom 和 sfo.pTo指向的字符串必须以2个0字符结尾。由于一开始我已经将Sou和Des全部清为0了,所以它们肯定是以2个0字符结尾的。 BOOL CMakeInstallFile::CopyNewFile(LPCTSTR pstr){ BOOL bResult = TRUE; CFileFind finder; CString strWildcard(pstr); strWildcard += _T("\\*.*"); // start working for files BOOL bWorking = finder.FindFile(strWildcard); while (bWorking) { bWorking = finder.FindNextFile(); if (finder.IsDots())continue; if (finder.IsDirectory()) { CString str = finder.GetFilePath(); CString strSource = str; strSource.Replace(m_strVssFilePath, m_strInstallFilePath); bResult = ::CreateDirectory(strSource, NULL); if(!bResult) { ErrorOccur(); } CopyNewFile(str); } else { CString strSource = finder.GetFilePath(); CString strTarget = strSource; strTarget.Replace(m_strVssFilePath, m_strInstallFilePath); bResult = ::CopyFile(strSource,strTarget,FALSE); MySetFileAttribute(strTarget); if(!bResult) { ErrorOccur(); } else { m_pProgressCtrl->StepIt(); } } } finder.Close(); return bResult;} 给你一个递归的CopyFolderAllFiles(CString csSourceFolder, CString csNewFolder){ CFileFind f; BOOL bFind=f.FindFile(csSourceFolder+"\\*.*"); while(bFind) { bFind = f.FindNextFile(); TRACE(_T("%s\r\n"),f.GetFileName()); if(f.IsDots()) continue; if(f.IsDirectory()) { _mkdir(csNewFolder+"\\"+f.GetFileName()); CopyFolderAllFiles(csSourceFolder+"\\"+f.GetFileName(),csNewFolder+"\\"+f.GetFileName()); } ::SetFileAttributes(csSourceFolder+"\\"+f.GetFileName(),FILE_ATTRIBUTE_NORMAL); ::AfxGetApp()->DoWaitCursor(1); ::CopyFile(csSourceFolder+"\\"+f.GetFileName(),csNewFolder+"\\"+f.GetFileName(),FALSE); ::AfxGetApp()->DoWaitCursor(-1); }} jishiping(JSP 季世平) 的方法SHFileOperation(&sfo);是个不错的方法 求助:在基于对话框的程序中,其中一个对话框中保存的几个变量值怎么传递到另一个对话框中继续使用啊?? 请教创建“线宽”组合框问题 Vs2005怎么设置bug提示是英文的 如何分割窗体并编程 在MFC单文档中,如何把原来显示的数据(比如控件,文字等)全部清空,如同新建的一样. 打印机问题,急!!!!!急!!!!! VC++6.0 F10单步调试的问题(郁闷中) 现有联通SGIP协议封装API出售,采用最新协议增加LinkID!云南省上门服务!有意者请联系! 如何打开一个AVI文件? 一个小算法的问题,急! 怎么样简单安装MSDN? 谁知道那里有关于AT命令集中文网站啊?要详细专业的!
FindNextFile
...如果是MFC的话直接用CFileFind...
char Des[_MAX_PATH];
SHFILEOPSTRUCT sfo;memset(Sou, 0, sizeof(Sou));
strcpy(Sou, "C:\\Dir1");
strcpy(Des, "C:\\Dir2"); //目录必须存在
memset(&sfo, 0, sizeof(sfo));
sfo.wFunc = FO_COPY;
sfo.pFrom = Sou;
sfo.pTo = Des;
SHFileOperation(&sfo);注意,sfo.pFrom 和 sfo.pTo指向的字符串必须以2个0字符结尾。由于一
开始我已经将Sou和Des全部清为0了,所以它们肯定是以2个0字符结尾的。
{
BOOL bResult = TRUE;
CFileFind finder; CString strWildcard(pstr);
strWildcard += _T("\\*.*"); // start working for files
BOOL bWorking = finder.FindFile(strWildcard); while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())continue;
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
CString strSource = str;
strSource.Replace(m_strVssFilePath, m_strInstallFilePath);
bResult = ::CreateDirectory(strSource, NULL);
if(!bResult)
{
ErrorOccur();
}
CopyNewFile(str);
}
else
{
CString strSource = finder.GetFilePath();
CString strTarget = strSource;
strTarget.Replace(m_strVssFilePath, m_strInstallFilePath);
bResult = ::CopyFile(strSource,strTarget,FALSE);
MySetFileAttribute(strTarget);
if(!bResult)
{
ErrorOccur();
}
else
{
m_pProgressCtrl->StepIt();
}
}
} finder.Close(); return bResult;
}
CopyFolderAllFiles(CString csSourceFolder, CString csNewFolder)
{
CFileFind f;
BOOL bFind=f.FindFile(csSourceFolder+"\\*.*");
while(bFind)
{
bFind = f.FindNextFile();
TRACE(_T("%s\r\n"),f.GetFileName());
if(f.IsDots()) continue;
if(f.IsDirectory())
{
_mkdir(csNewFolder+"\\"+f.GetFileName());
CopyFolderAllFiles(csSourceFolder+"\\"+f.GetFileName(),csNewFolder+"\\"+f.GetFileName());
}
::SetFileAttributes(csSourceFolder+"\\"+f.GetFileName(),FILE_ATTRIBUTE_NORMAL);
::AfxGetApp()->DoWaitCursor(1);
::CopyFile(csSourceFolder+"\\"+f.GetFileName(),csNewFolder+"\\"+f.GetFileName(),FALSE);
::AfxGetApp()->DoWaitCursor(-1);
}
}
是个不错的方法