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
.
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:
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 extensionxcopy will allow you to copy a single file into a specifed folder it just wont allow you to define a destination name. If you require the destination name just rename it before you copy it.
ren "bin\development\whee.config.example" whee.config
xcopy /R/Y "bin\development\whee.config" "TestConnectionExternal\bin\Debug\"
I had a similar issue and both robocopy and xcopy did not help, as I wanted to suppress the comments and use a different destination filename. I found
working as per my requirements.
So, there is a simple fix for this. It is admittedly awkward, but it works. xcopy will not prompt to find out if the destination is a directory or file IF the new file(filename) already exists. If you precede your xcopy command with a simple echo to the new filename, it will overwrite the empty file. Example
Since you're not actually changing the filename, you can take out the filename from the destination and there will be no questions.
This approach works well when the destination directory is guaranteed to exist, and when the source may equally be a file or directory.
Use copy instead of xcopy when copying files.
e.g. copy "bin\development\whee.config.example" "TestConnectionExternal\bin\Debug\whee.config"