Is it possible to make a console application that copies a specified file to another drive? for example to copy C:\useless.txt to A:\
Please if anyone knows how to do it of its even possible.... reply.
Thanx
Printable View
Is it possible to make a console application that copies a specified file to another drive? for example to copy C:\useless.txt to A:\
Please if anyone knows how to do it of its even possible.... reply.
Thanx
?Code:#include <stdio.h>
int main()
{
system("copy file.txt a:\file.txt");
return 0;
}
Im using Dev C++ and it gives me 1 error "implicit declaration of function 'int system(...)'
It's in stdlib.h
Point your cursor at the function name and press F1
now it complies without errors but then in the console window it says: The system cannot find the specified file.
I have the file.txt in the directory but it just wont work. this is the code im using
----------------------------------------------------------
#include <stdlib.h>
int main()
{
system("copy file.txt a:\file.txt");
system("PAUSE");
return 0;
}
------------------------------------------------------------
It Works Now Thanx. i just had to take the file.txt out of "a: file.txt" for future reference the code is.
#include <stdlib.h>
int main()
{
system("copy file.txt a:");
return 0;
}
It also works on folders.
Thought i would let you knowCode:#include <stdlib.h>
int main()
{
system("copy test a:");
system("PAUSE");
return 0;
}
Test being your folder. :)
Only problem i have found it doesn't copy the folder.
Also i would like to ask.... would it be possible to be able to make a program that would copy files to a CD-RW? Must be a way but i don't know how.
I wrote a copy program here for someone asking about it on the C board.
It does the copy using standard C coding (expect for assuming you have backslashes as directory markers in the filenames, which obviously won't work on a *nix box). It's a bit safer than calling system, although a lot more long winded.
It's not guarenteed to be bullet proof, but it's a start.
:)
If youre going to use \ in a program, double it ( \\) or else it will be called an unknown escape ¿function?
I take it you mean this line:Quote:
Originally posted by civix
If youre going to use \ in a program, double it ( \\) or else it will be called an unknown escape ¿function?
>if ((p = strrchr(in, '\\')) == NULL)
The thing is, I did use 2, I wouldn't post code that is that badly broken ;)
But the board transposed it to a single slash for some reason. So I've edited the post and put 3 slashes in the source of my post, just to make it display 2 to everyone else :rolleyes:
Thanks for pointing it out, at least I know to be careful of this in the future.
Code:Testing : 1 slash : '\'
Testing : 2 slashes : '\\'
Testing : 3 slashes : '\\\'
Testing : 4 slashes : '\\\\'