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(command,"xcopy ");
     strcat(command," ");
     strcat(command," \\s \\i \\q");

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.

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.

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");
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 3 Years Ago by happygeek: fixed formatting (inline code)

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

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 article has been dead for over six months. Start a new discussion instead.