xcopy file, rename, suppress “Does xxx specify a f

2019-01-05 07:33发布

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.

19条回答
家丑人穷心不美
2楼-- · 2019-01-05 08:06

XCOPY with * at the end of the target to copy files whether they exist or not in destination XCOPY with \ at the end of the target to copy folders and contents whether exist or not in destination

Alternatively

RoboForm SOURCE DEST FILE for files RoboForm SOURCE DEST for folders

查看更多
The star\"
3楼-- · 2019-01-05 08:07

The right thing to do if you wanna copy just file and change it's name at destination is :

xcopy /f /y "bin\development\example.exe" "TestConnectionExternal\bin\Debug\NewName.exe*"

And it's Gonna work fine

查看更多
疯言疯语
4楼-- · 2019-01-05 08:09

I suggest robocopy instead of copy or xcopy. Used as command or in GUI on clients or servers. Tolerant of network pauses and you can choose to ignore file attributes when copying of copy by file attributes. Oh, and it supports multi-core machines so files are copied much faster in "parallel" with each other instead of sequentially. robocopy can be found on MS TechNet.

查看更多
来,给爷笑一个
5楼-- · 2019-01-05 08:13

For duplicating large files, xopy with /J switch is a good choice. In this case, simply pipe an F for file or a D for directory. Also, you can save jobs in an array for future references. For example:

$MyScriptBlock = {
    Param ($SOURCE, $DESTINATION) 
    'F' | XCOPY $SOURCE $DESTINATION /J/Y 
    #DESTINATION IS FILE, COPY WITHOUT PROMPT IN DIRECT BUFFER MODE
}
JOBS +=START-JOB -SCRIPTBLOCK $MyScriptBlock -ARGUMENTLIST $SOURCE,$DESTIBNATION
$JOBS | WAIT-JOB | REMOVE-JOB

Thanks to Chand with a bit modifications: https://stackoverflow.com/users/3705330/chand

查看更多
6楼-- · 2019-01-05 08:17

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.

查看更多
Deceive 欺骗
7楼-- · 2019-01-05 08:17

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.

查看更多
登录 后发表回答