mardi 10 mars 2020

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. I use the method "CopyFile" but i have an issue whith the name of the file copied; 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". 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 :

 rename(destination_path.c_str(), source_path.c_str());

Thanks,

Aucun commentaire:

Enregistrer un commentaire