我有一个简单的副本从脚本到我们的一个人丢失了距离我的桌子20公里的文件
在测试脚本时,如果我的文件shapes.atc是文件或文件夹,则会提示我
我可以告诉你它是一个文件,但我怎样才能将它自动复制到我的家伙需要只需点击完成的批处理
xcopy /s/y J:\"My Name"\"FILES IN TRANSIT"\JOHN20101126\"Missing file"\Shapes.atc C:\"Documents and Settings"\"His name"\"Application Data"\Autodesk\"AutoCAD 2010"\"R18.0"\enu\Support\Shapes.atc
Run Code Online (Sandbox Code Playgroud)
Gov*_*ert 173
一个看似无法记录的技巧是将目标放在*目的地的末尾 - 然后xcopy将其复制为文件,就像这样
xcopy c:\source\file.txt c:\destination\newfile.txt*
Run Code Online (Sandbox Code Playgroud)
这个echo f | xcopy ...技巧不适用于Windows的本地化版本,其提示不同.
Cha*_*esB 22
实际上xcopy不会询问您原始文件是否存在,但是如果您想将其放在名为Shapes.atc的新文件夹中,或者在文件夹Support中(这是您想要的).
为了防止xcopy问这个,只需告诉他目标文件夹,所以没有歧义:
xcopy /s/y "J:\Old path\Shapes.atc" "C:\Documents and Settings\his name\Support"
Run Code Online (Sandbox Code Playgroud)
如果要更改目标中的文件名,只需使用copy(复制文件时比xcopy更适应):
copy /y "J:\Old path\Shapes.atc" "C:\Documents and Settings\his name\Support\Shapes-new.atc
Run Code Online (Sandbox Code Playgroud)
Den*_*vin 11
echo f | xcopy /s/y J:\"My Name"\"FILES IN TRANSIT"\JOHN20101126\"Missing file"\Shapes.atc C:\"Documents and Settings"\"His name"\"Application Data"\Autodesk\"AutoCAD 2010"\"R18.0"\enu\Support\Shapes.atc
Run Code Online (Sandbox Code Playgroud)
小智 11
真正的诀窍是:在目标路径末尾使用反斜杠来复制文件.如果您不想要警告,/ Y用于覆盖现有文件.
例:
xcopy /Y "C:\file\from\here.txt" "C:\file\to\here\"
Run Code Online (Sandbox Code Playgroud)
对于强制文件,我们可以使用管道"echo F |" :
C:\Trash>xcopy 23.txt 24.txt
Does 24.txt specify a file name
or directory name on the target
(F = file, D = directory)?
C:\Trash>echo F | xcopy 23.txt 24.txt
Does 24.txt specify a file name
or directory name on the target
(F = file, D = directory)? F
C:23.txt
1 File(s) copied
Run Code Online (Sandbox Code Playgroud)
为了强制文件夹,我们可以使用/ i参数进行xcopy或使用目标文件夹末尾的反斜杠().