复制目录内容 [英] Copy directory content

查看:79
本文介绍了复制目录内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将目录(tmp1)的内容复制到另一个目录(tmp2). tmp1可能包含文件和其他目录.我想使用C/C ++复制tmp1的内容(包括模式).如果tmp1包含目录树,则要递归复制它们.

I want to copy the content o directory(tmp1) to another directory(tmp2). tmp1 may contain files and others directories. I want to copy the content of tmp1 (including the mode) using C/C++. If tmp1 contains a tree of directories I want to copy them recursively.

最简单的解决方案是什么?

What is the simplest solution?

我找到了一种打开目录并读取每个条目并使用cp命令将其复制的解决方案.还有更简单的解决方案吗?

I found a solution to open the directory and read every entry and copy it with cp command. Any simpler solutions?

推荐答案

我建议使用std::filesystem(从C ++ 17合并到ISO C ++!)

I recommend using std::filesystem (merged to ISO C++ as of C++17!)

http://en.cppreference.com/w/cpp/文件系统/复制:

std::filesystem::copy("/dir1", "/dir3", std::filesystem::copy_options::recursive);

详细了解它:

https://gcc.gnu.org /onlinedocs/gcc-6.1.0/libstdc++/api/a01832.html

experimental :: filesystem链接器错误

这篇关于复制目录内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆