Hey, does anyone know which function/s i need to use to copy a file from one subdirectory to another, without changing the name? im on windows if that helps.

You can use system() command to do that.

system("//copy file.txt folder");

Edited 5 Years Ago by Arbus: n/a

Its just telling me my syntax is incorrect.

system("//copy subdirectory/file.txt subdirectory2");

Edited 5 Years Ago by lexusdominus: n/a

I meant system("copy file.txt folder");
// i gave that as a comment.
For example...

system("copy myfile.txt c:\my\location");

Edited 5 Years Ago by Arbus: n/a

ok, but what if the file i want to copy is in a subdirectory. do i have to give the full path of the file? because i want this program to work if it is anywhere on the hard drive. also, what do i need to put if i want to copy it from the subdirectory to the program directory?

1) If you want the program to work from anywhere on the system. And the file is surely found at the same path. you should prefer writing down the whole path.

2) If the file is in a subdirectory of your program directory. Consider
progdir->subdir->abc.txt
And you want to copy it down into the progdir (Where your program is running from)
then ,

system("copy .\subdir\abc.txt abc.txt");

should do fine.

sorry, i dont want to sound anal, but could you be a little more specific? its telling me the file cannot be found.

system("copy .\subdir\abc.txt abc.txt"); /*copy to program directory from subdirectory?*/
system("copy .\subdir\abc.txt .\subdir2\abc.txt"); /*copy from subdirectory to subdirectory?*/

Edited 5 Years Ago by lexusdominus: n/a

sorry, i dont want to sound anal, but could you be a little more specific? its telling me the file cannot be found.

You don't know what a full path is?

And to fix your code

system("copy .\\subdir\\abc.txt abc.txt"); /*copy to program directory from subdirectory?*/
system("copy .\\subdir\\abc.txt .\\subdir2\\abc.txt"); /*copy from subdirectory to subdirectory?*/

i assumed that a full path was the full path to the file includng drive letter, eg c:\program\data\file.txt

But since you mention it, what is a full path?

yeah its working now, thanks. is it possible to get it to work silently and not output text to the console (1 file(s) copied)

cool thanks. Is there anyway to get it to run without outputting text? (1 file(s) copied)

This article has been dead for over six months. Start a new discussion instead.