# xcopy Not Surpressing File/Directory Query

I'm attempting to use xcopy to copy over a file from one machine to another on our network as part of a Java program. I'm calling xcopy like this:

xcopy "C:\Program Files\path\to\my\file" "\\othermachine\c$\Documents and Settings\<myUserName>\Desktop\Test\path\in\directory\structure\to\file" /e /y /i  Because I'm calling it from with in Java, I need all the prompts to be suppressed. For the most part, \i and \y have done exactly that. However, for this one file /i fails and I get the file or directory prompt. The result is that it hangs the entire program. I've also tried calling it with /s /t /q appended on to the existing options, to no avail. Why isn't /i working to suppress the File or Directory prompt? Is there an order I need to call the options in? Is there something else I need to do? EDIT: I should mention, the file is a text file - single line of text. It does not have an extension. It looks like this: FILE-NAME ## 5 Answers echo F does the trick: echo F | xcopy "C:\Program Files\path\to\my\file" "\\othermachine\c$\Documents and Settings\<myUserName>\Desktop\Test\path\in\directory\structure\to\file" /e /y /i


Note that the character may differ in localized versions (my german one expects D for file (Datei) or V for directory (Verzeichnis))

• 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 Jun 19 '18 at 9:33

A seemingly undocumented trick is to put a * at the end of the destination - then xcopy will copy as a file, so

xcopy c:\source\file.txt c:\destination\newfile.txt*

The echo f | xcopy ... trick does not work on localized versions of Windows, where the prompt is different.

• echo f at least works on Russian Win 8.1 // PS. The asterisk trick works, I can only wonder who could ever discover it! I bet it is a bug in xcopy that is [ab]used to compensate for the lack of a needed feature – Arioch 'The Jun 19 '18 at 9:34

• Thanks for the suggestion, but that's a rather different scenario. That's suppressing the terminal itself when calling a batch file. I'm trying to suppress a prompt that xcopy gives. – Daniel Bingham Sep 2 '09 at 14:30

I've always found a useful cheat for these situations to have a text file with a Y in it and tag < y.txt on the end of the xcopy

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.