代码之家  ›  专栏  ›  技术社区  ›  Sijith

文件夹复制VC++

  •  4
  • Sijith  · 技术社区  · 14 年前

    我要将目录从一个驱动器复制到另一个驱动器。 我选择的目录包含许多子目录和文件。 如何使用vc实现相同的功能++

    3 回复  |  直到 14 年前
        1
  •  5
  •   Hans Passant    14 年前

    这个 SHFileOperation() api函数是复制文件的主力函数。它支持递归目录。查看中可用的选项 SHFILEOPSTRUCT 结构来控制副本。

        2
  •  0
  •   shoosh    14 年前

    艰难的道路。单独复制每个文件。

    使用 FindFirst() FindNext() 遍历目录的内容 使用 SetCurrentDirectory() 进出目录
    使用 CreateDirectory() 创建新文件夹树
    最后,使用 CopyFile() 复制实际文件

        3
  •  -1
  •   nabulke    14 年前

    如果您可以访问Boost库,这是您的朋友:

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

    查看教程中使用文件系统迭代器的好例子。

    开始:

    #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;
      }