xcopy file, rename, suppress "Does xxx specify a file name..." message

This seems pretty simple and maybe I'm just overlooking the proper flag, but how would I, in one command, copy a file from one directory to another and rename it in the destination directory? Here's my command:

if exist "bin\development\whee.config.example"
  if not exist "TestConnectionExternal\bin\Debug\whee.config"
    xcopy "bin\development\whee.config.example"
          "TestConnectionExternal\bin\Debug\whee.config"

It prompts me with the following every time:

Does TestConnectionExternal\bin\Debug\whee.config specify a file name or directory name on the target (F = file, D = directory)?

I want to suppress this prompt; the answer is always F.


I use

echo f | xcopy /f /y srcfile destfile

to get around it.


Don't use the xcopy, use copy instead, it doesn't have this issue.

xcopy is generally used when performing recursive copies of multiple files/folders, or when you need the verification/prompting features it offers. For single file copies, the copy command works just fine.


Another option is to use a destination wildcard. Note that this only works if the source and destination filenames will be the same, so while this doesn't solve the OP's specific example, I thought it was worth sharing.

For example:

xcopy /y "bin\development\whee.config.example" "TestConnectionExternal\bin\Debug\*" 

will create a copy of the file "whee.config.example" in the destination directory without prompting for file or directory.

Update: As mentioned by @chapluck:

You can change "* " to "[newFileName].*". It persists file extension but allows to rename. Or more hacky: "[newFileName].[newExt]*" to change extension


There is some sort of undocumented feature in XCOPY. you can use:

xcopy "bin\development\whee.config.example" "c:\mybackup\TestConnectionExternal\bin\Debug\whee.config*"

i tested it just today. :-)


Just go to http://technet.microsoft.com/en-us/library/bb491035.aspx

Here's what the MAIN ISSUE is "... If Destination does not contain an existing directory and does not end with a backslash (), the following message appears: ...

Does destination specify a file name or directory name on the target (F = file, D = directory)?

You can suppress this message by using the /i command-line option, which causes xcopy to assume that the destination is a directory if the source is more than one file or a directory.

Took me a while, but all it takes is RTFM.