One more possible trick is pre-creation of a target file or folder. Then xcopy
would not ask, because it would already know.
I would not say this solution is better than ones mentioned above, it is just different and hence I want it to be had here too.
My own simple task was copying a number of files from a network folder to a local accumulating folder.
- AAAAA\Disk1.zip => AAAAA.zip
- BBBBB\Disk1.zip => BBBBB.zip
- et cetera
Original command (one line of a slightly longer .cmd script file) was
for /d /r %SRC% %%1 in (*.*) do xcopy /k /f /y %%1\Disk1.zip %~dp0%%~nx1.zip
That however spawns a lot of those (F)ile-or(D)-irectory questions on a first use with new (not met before) files. Especially if I am populating a new empty target folder.
Then the echo F
and Asterisk Hack answers - they work fine too.
for /d /r %SRC% %%1 in (*.*) do echo f | xcopy /k /f /y %%1\Disk1.zip %~dp0%%~nx1.zip
for /d /r %SRC% %%1 in (*.*) do xcopy /k /f /y %%1\Disk1.zip %~dp0%%~nx1.zip*
Now, yet one more potential solution would be explicitly CREATING the target folder of file right before issuing the xcopy
command.
For file it would be, for example:
echo. > C:\Temp\TargetPlace
xcopy Source C:\Temp\TargetPlace
Sadly Windows by default does not have touch
command, quite useful to create dummy 0-bytes file.
For folder it would be, for example:
mkdir C:\Temp\TargetPlace
xcopy Source C:\Temp\TargetPlace
Granted, it takes two commands - two lines - in CMD shell script.
You can not put multiple commands into CMD for loop easily, but here you can pipe the commands together (providing that xcopy
would NOT actually read any user input when issued the specific command, which might change for example in future Window versions, albeit unlikely).
For folders:
for /d /r %SRC% %%1 in (*.*) do md %~dp0%%~nx1.zip | xcopy /k /f /y %%1\Disk1.zip %~dp0%%~nx1.zip
For files:
for /d /r %SRC% %%1 in (*.*) do echo. >%~dp0%%~nx1.zip | xcopy /k /f /y %%1\Disk1.zip %~dp0%%~nx1.zip
This last command has TWO output redirections in between - echo.
> ... | xcopy
. But at least in .cmd
files of Windows 8.1 it works.
no localization, it is still the same letter in Win 8 rus. However it is annoying. I'd prefer xcopy used
/-i
option to suppress this stupid question. – Arioch 'The – 2018-06-19T09:33:03.123