Copying a file without prompting the user

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
hacxx
Posts: 57
Joined: 09 Apr 2015 13:18

Copying a file without prompting the user

#1 Post by hacxx » 22 May 2015 04:47

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

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Copying a file without prompting the user

#2 Post by npocmaka_ » 22 May 2015 04:58

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copying a file without prompting the user

#3 Post by foxidrive » 23 May 2015 00:08

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.

Ben Mar
Posts: 22
Joined: 03 May 2015 10:51

Re: Copying a file without prompting the user

#4 Post by Ben Mar » 23 May 2015 08:08

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copying a file without prompting the user

#5 Post by foxidrive » 23 May 2015 08:15

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.

Ben Mar
Posts: 22
Joined: 03 May 2015 10:51

Re: Copying a file without prompting the user

#6 Post by Ben Mar » 23 May 2015 08:40

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

hacxx
Posts: 57
Joined: 09 Apr 2015 13:18

Re: Copying a file without prompting the user

#7 Post by hacxx » 23 May 2015 12:16

Thanks,

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

Post Reply