Folder copy VC++

2019-06-25 04:41发布

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++

3条回答
可以哭但决不认输i
2楼-- · 2019-06-25 05:15

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.

查看更多
Bombasti
3楼-- · 2019-06-25 05:19

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

查看更多
戒情不戒烟
4楼-- · 2019-06-25 05:35

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;
  }
查看更多
登录 后发表回答