我有以下文件夹结构:
Folder1
-Folder2
-File1
-File2
-File3
我在批处理脚本中尝试了以下内容来复制Folder1中的所有内容
echo d | xcopy "Folder1\*.*" "DestinationFolder"/f /s /y /r
但我只需要复制File1,File2,File3。需要忽略Folder2。我对如何实现这一目标一无所知。请帮我解决这个问题。
如果Folder2为空,/S
会这样做,
但由于你的命令中有/s
,所以我猜它不是空的。
所以使用这个:
echo \Folder2\>__tmp4Exclude__
echo d | xcopy "Folder1\*.*" "DestinationFolder" /f /s /y /r /EXCLUDE:__tmp4Exclude__
del __tmp4Exclude__
__tmp4Exclude__
是一个临时文件,用于包含复制时要排除的文件列表。
来自xcopy /?
:
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. Each string
should be in a separate line in the files. When any of the
strings match any part of the absolute path of the file to be
copied, that file will be excluded from being copied. For
example, specifying a string like \obj\ or .obj will exclude
all files underneath the directory obj or all files with the
.obj extension respectively.
没有必要使用xcopy
来复制文件! xcpoy
通常用于复制目录树。
所以,改用copy
。你可以做:
copy "Folder1\*.*" "Destination\"
可能你可能需要使用/(-)Y
选项:
/Y
禁止提示您确认是否要覆盖现有目标文件。/-Y
导致提示您确认要覆盖现有目标文件。
来自copy /?
(copy
帮助页面)