[英]CopyFile from one directory to another (C++)
i'm working on Windows and i'm trying to simply move a file from one directory to another.我在 Windows 上工作,我试图简单地将文件从一个目录移动到另一个目录。 I use the method "CopyFile" but i have an issue whith the name of the file copied;我使用“CopyFile”方法,但我有复制文件名称的问题; i'm trying this:我正在尝试这个:
#include <windows.h>
#include <stdio.h>
std::string source_path = "C:/ProgramData/RTD02/versions/versions.txt";
std::string destination_path = "C:/ProgramData/RTD02/principale.txt";
CopyFile(source_path.c_str(), destination_path.c_str(), 0);
In fact the content of the file "versions.txt" is well copied into the file "principale.txt".事实上,文件“versions.txt”的内容被很好地复制到文件“principale.txt”中。 But what i want is also to change the name of file "principale.txt" to "versions.txt", i tried this one but it didn't work :但我想要的也是将文件“principale.txt”的名称更改为“versions.txt”,我尝试了这个,但没有用:
rename(destination_path.c_str(), source_path.c_str());
Thanks,谢谢,
The answer is that your destination string needs to be, well the destination.答案是您的目标字符串必须是目标。
std::string destination_path = "C:/ProgramData/RTD02/versions.txt";
If you meant to replace an existing file you then follow up a successful copy with DeleteFile
the principale.txt
如果您打算替换现有文件,那么您可以使用DeleteFile
the principale.txt
成功复制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.