Page 1 of 1

Copying a file without prompting the user

Posted: 22 May 2015 04:47
by hacxx
Hi,

What is the best way to copy a file without prompting the user?

I have tried
xcopy intro.exe %userprofile%\intro.exe

but the user needs to specify if it's a folder or a file.

Thanks

Re: Copying a file without prompting the user

Posted: 22 May 2015 04:58
by npocmaka_

Code: Select all

echo f|xcopy intro.exe %userprofile%\intro.exe


but could be language settings dependent.And using xcopy for single files is a bad practice. Better use copy:

Code: Select all

copy /y  intro.exe %userprofile%\intro.exe

Re: Copying a file without prompting the user

Posted: 23 May 2015 00:08
by foxidrive
npocmaka_ wrote:using xcopy for single files is a bad practice.


It may seem odd, npocmaka, but I can't see any reason why it would be a bad practice.

I think xcopy uses larger buffers than copy, which could make it more efficient.

Re: Copying a file without prompting the user

Posted: 23 May 2015 08:08
by Ben Mar
hacxx wrote:Hi,

What is the best way to copy a file without prompting the user?

I have tried
xcopy intro.exe %userprofile%\intro.exe

but the user needs to specify if it's a folder or a file.

Thanks

How about just doing this?

Code: Select all

xcopy intro.exe %userprofile%  /y

There will be no prompt to bother at all.

Re: Copying a file without prompting the user

Posted: 23 May 2015 08:15
by foxidrive
Ben Mar wrote:How about just doing this?

Code: Select all

xcopy intro.exe %userprofile%  /y

There will be no prompt to bother at all.


It needs double quotes to protect against spaces etc, to be robust.

Re: Copying a file without prompting the user

Posted: 23 May 2015 08:40
by Ben Mar
You're right foxidrive. I forgot about the possibility of space(s) in the path.
Thanks :D

Code: Select all

xcopy intro.exe "%userprofile%"  /y

Re: Copying a file without prompting the user

Posted: 23 May 2015 12:16
by hacxx
Thanks,

I'm using xcopy intro.exe "%userprofile%" /y