Folder copy VC++

六月ゝ 毕业季﹏ 提交于 2019-12-13 13:21:46

问题


i want to copy a directory from one drive to another drive. My selected directory contain many sub directories and files. How can i implement the same using vc++


回答1:


The SHFileOperation() API function is the workhorse function for copying files. It supports recursing directories. Review the options available in the SHFILEOPSTRUCT structure to control the copy.




回答2:


The hard way. copy every file individually.

Use FindFirst() and FindNext() to iterate over the content of a directory Use SetCurrentDirectory() to go in and out of directories
Use CreateDirectory() to create the new folders tree
and finally, use CopyFile() to copy the actual files




回答3:


If you have access to the boost library this is your friend:

http://www.boost.org/doc/libs/1_42_0/libs/filesystem/doc/index.htm

Check the tutorial for nice examples using a filesystem iterator.

To get you started:

#include <iostream>
#include “boost/filesystem.hpp”
int main(int argc, char *argv[])
  {
  boost::filesystem::path path1("/usr/local/include"); // your source path
  boost::filesystem::path::iterator pathI = path1.begin();
  while (pathI != path1.end())
    {
    std::cout << *pathI << std::endl; // here you could copy the file or create a directory
    ++pathI;
    }
  return 0;
  }


来源:https://stackoverflow.com/questions/2536411/folder-copy-vc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!