Assuming it is Windows, something like this:
const std::string path = "C:\\some_dir\\another_dir\\" ;
const std::string srce_pattern = "*.txt" ;
const std::string dest_file_name = "merge.txt" ;
std::system( ( "del " + path + dest_file_name ).c_str() ) ;
std::system( ( "copy /a " + path + srce_pattern + " " + path + dest_file_name ).c_str() ) ;
Note: There is nothing wrong in using
or in general one program invoking another program (fork/exec, CreateProcess etc.).
In security concious code, precautions have to be taken:
The environment (PATH etc) has to be sanitized before invoking external programs.
If the data to be passed to external programs (the command string in
) come from unreliable sources, it has to be sanitized too.
And privileges have to be dropped to the minimum level required before invocation (do not run as root etc.)
Doing all this is somewhat difficult; so if an alternative is available (for example library calls) it is better to use that rather than invoking an external program to do the job.