- CString sourcePath("D:\\test");
- CString firstFolder=sourcePath.Mid(sourcePath.ReverseFind('\\')+1);
- CString targetFolder;
- targetFolder.Format("%s\\%s","E:",firstFolder);
- if (CreateDirectory(targetFolder,NULL))
- {
- CStringList copyfiles;
- copyfiles.AddTail(sourcePath);
- long sourceDirLen=sourcePath.GetLength();
- while (copyfiles.GetCount()>0)
- {
- CString fn;
- fn.Format("%s\\*.*",copyfiles.GetHead());
- CFileFind fd;
- BOOL bWorking = fd.FindFile(fn);
- copyfiles.RemoveHead();
- while (bWorking)
- {
- bWorking = fd.FindNextFile();
- if(!fd.IsDots())
- {
- if(fd.IsDirectory())
- {
- CString subdirectory=fd.GetFilePath();
- copyfiles.AddTail(subdirectory);
- CString newfolder=targetFolder+subdirectory.Mid(sourceDirLen);
- CreateDirectory(newfolder,NULL);
- }
- else
- {
- CString filepath=targetFolder+fd.GetFilePath().Mid(sourceDirLen);
- CFile createFile;
- createFile.Open(filepath,CFile::modeCreate|CFile::modeWrite);
- createFile.Close();
- }
- }
- }
- fd.Close();
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/121220137984.html
来源: http://www.codesnippet.cn/detail/121220137984.html