[英]boost filesystem copy_file “successful” but no files copied
im having trouble figuring out why my files wont copy. 我在弄清楚为什么我的文件无法复制时遇到麻烦。 Here's a brief portion of the code:
这是代码的简短部分:
( dir_itr
is directory_iterator & root
is a path) (
dir_itr
是directory_iterator,而root
是路径)
if (!(is_directory(dir_itr->path())))
{
cout << "copying: " << dir_itr->path().filename() << endl;
try
{
copy(dir_itr->path(), root);
remove(dir_itr->path());
} catch (filesystem_error& ex) {
//more code
The results are as follows in the command window: 结果在命令窗口中如下所示:
boost::filesystem::copy_file: The operation completed successfully:
"C:\Documents and Settings\R\Desktop\New Folder\New Folder (2)\New Bitmap Image 3.bmp",
"C:\Documents and Settings\R\Desktop\New Folder"
However no files are copied over. 但是,没有文件被复制。
I am basically just trying to move said file from folder c:\\x\\y\\file.file
to c:\\x
我基本上只是想将所述文件从文件夹
c:\\x\\y\\file.file
到c:\\x
I'm assuming why i cant move it is because i need a full file name and not just a directory or something? 我假设为什么我不能移动它是因为我需要一个完整的文件名,而不仅仅是目录或其他内容? If this is the case, how do i convert path root to string so i can add a file name to it?
在这种情况下,如何将路径根转换为字符串,以便可以向其中添加文件名? (im gettin a thousand errors if i even try, they're so long i cant scroll all the way back up the window to see where it starts)
(如果我什至尝试,我会收到一千个错误,它们是如此之久,以至于我无法一直滚动到整个窗口以查看其开始位置)
Perhaps boost::filesystem::system_complete can help: 也许boost :: filesystem :: system_complete可以帮助:
(Sorry, I'm on my Mac and not windows but it shows a way to get the absolute path from a relative path). (对不起,我在Mac上而不是Windows上,但是它显示了一种从相对路径获取绝对路径的方法)。 Good luck.
祝好运。
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
int main(int argc, char *argv[]) {
boost::filesystem::path cwd(".");
boost::filesystem::path resolved = boost::filesystem::system_complete(cwd);
std::cout << cwd << std::endl;
std::cout << resolved << std::endl;
}
Outputs: 输出:
"."
"/private/var/folders/qw/x23nm9f11fxc45rgddb04n_w0000gn/T/CodeRunner/."
Got back to working on this and I added/changed the following: 回到工作上,我添加/更改了以下内容:
try
{
string temp = root.string() + "\\" + dir_itr->path().filename().string();
path p(temp);
copy(dir_itr->path(), p);
remove(dir_itr->path());
//more code
And it seemed to work. 它似乎有效。 I guess my assumption of needing to include the file name when copying was correct.
我猜想我的假设是在复制正确时需要包括文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.