0

Hello all,

 I am working on a project and i need to basically copy a directory and its files to another location. I have figured out that xcopy comes in handy for what i want to do.but somehow when incorporated into my C code, it does not work. The code is this: 


     strcpy(src,"c:\\YeSQL\\");
     strcat(src,"db1");
     strcat(src,"\\*");
     strcpy(dest,"c:\\YeSQLBackUp");
     strcpy(command,"xcopy ");
     strcat(command,src);
     strcat(command," ");
     strcat(command,dest);
     strcat(command," \\s \\i \\q");
     printf("\n\n\n%s",command);
     system(command);
4
Contributors
6
Replies
32
Views
3 Years
Discussion Span
Last Post by necrovore
0

Actually, it's in Windows 7. Open a command window and type xcopy /? for all the info on it. Obviously, naming the files you want to move, and where you want to move them to, is critical.

That being said, I believe you'll enjoy programming it in C, instead, and learn something new in the process.

0

Yea, you are right. When I tried it I mis-read the error message, thinking it said "command not found". That's what I get for not reading more carefully.

0

Thank you for your inputs Ancient Dragon and Adak. I figured out the mistake in my code.
I just had to replace
strcat(command," \\s \\i \\q");
with
strcat(command," /s /i /q");

That part is done. now i have stumbled on another problem.
when the files already exist and i run the same function again, i get a prompt from xcopy asking me if i want to rewrite. I want to suppress this prompt.
I already tried

strcat(command," /s /i /q /y");

But it is not working. Could you give me a better option to supress this prompt?

Thank you!

Edited by happygeek: fixed formatting (inline code)

0

It's a little sneaky, but you could pipe an answer to xcopy. It doesn't suppress the prompt, but it does execute it automatically:

echo F | xcopy /s /i /q /y src dst
0

thank you deceptikon, did not know that was even possible. Thanks a lot. but i got it workinng without echo. strcat(command," /s /i /q /y"); worked. It was my negligence not to have checked it properly before posting it here. Sorry, if this was an inconvinience.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.