[英]how to copy directory of specific files in batch file
c:/--> folder1-->
folder2->
img001.png
img002.jpg
img003.png
I having kind of folder structure. 我有一种文件夹结构。
I need to copy a single file from this folder to Destination folder. 我需要将单个文件从该文件夹复制到目标文件夹。
source : "c:\folder1\folder2\imgoo1.png"
Destination:"D:\folder1\folder2\imgoo1.png"
need output: 需要输出:
D:/--> folder1-->
folder2->
img001.png
Note:I need batch file format 注意:我需要批处理文件格式
for %%f in (img001.png img002.jpg img003.png) do copy /b "c:\folder1\folder2\%%f" "d:\folder1\folder2\"
Note that thw directory separator in windows is \\
, not /
. 请注意,Windows中的目录分隔符为
\\
,而不是/
。 /
is used as a command-switch - /b
in the above case means "copy in binary mode'. /
用作命令开关-在上述情况下, /b
表示“以二进制模式复制”。
Note that you do not say whether the batch should check whether the destination directory exists or whether the destination filename already exists. 请注意,您没有说该批处理是否应检查目标目录是否存在或目标文件名是否已经存在。
md "d:\folder1\folder2" 2>nul
will force the destination filename to exist ( 2>nul
suppresses the 'already exists ' message) 将强制目标文件名存在(
2>nul
禁止显示“已经存在”消息)
You can add an extra switch /y
to the copy
command to force overwrite in the case that the destination file already exists. 您可以在
copy
命令中添加一个额外的开关/y
以在目标文件已存在的情况下强制覆盖。
You can add >nul
to the copy
command to suppress the 1 file copied
message. 您可以在
copy
命令中添加>nul
以禁止1 file copied
消息。
robocopy "c:\folder1\folder2" "d:\folder1\folder2" "img0001.jpg"
由于robocopy不包含在Windows XP中,因此可以使用普通xcopy来完成。
xcopy "c:\folder1\folder2\img0001.jpg" "d:\folder1\folder2\"
This will copy that one file. 这将复制该文件。 The target filename is not required but can be left in.
目标文件名不是必需的,但可以保留。
copy "c:\folder1\folder2\imgoo1.png" "D:\folder1\folder2\imgoo1.png"
This assumes that the folders already exist. 这假定文件夹已经存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.