How to use C++ to Copy A Directory [duplicate] How to use C++ to Copy A Directory [duplicate] windows windows

How to use C++ to Copy A Directory [duplicate]


As of today, C++17's <filesystem> is the proper solution.

#include <filesystem>int main(){    std::filesystem::copy("C:/Users/", "E:/Backup/");}

The slashes (/) are interpreted as directory separators, this is easier to read than a double back-slash (\\).


The approach using System will not be platform independent. I strongly recommend using boost::filesystem for such tasks.


1) include .h files:

#include <csystem>

2) write cmd:

system("copy c:\users\ e:\Backup\");

Tips: You can write everything in " " , just like you copy directorys in cmd.