繁体   English   中英

批量查找文件,将文件复制到另一个目录

[英]Batch to find file, copy file to another directory

我的问题与此处在stackoverflow上发布的问题非常相似,但对我而言,不同之处在于我需要批处理脚本来执行以下操作

  1. 查看仅具有名称而没有图像扩展名的csv文件,然后在特定目录中找到具有该名称的图像
  2. 然后获取该文件并将其复制到另一个目录

为了完成该任务,我需要对该批处理脚本进行哪些修改?

 @echo off 
 for /f "tokens=1,2 delims=," %%j in (project.csv) do ( 
   copy "%%j.jpg" c:\mytestproject\newimages 
   rename c:\mytestproject\newimages\%%j.jpg" %%k.jpg 
 )

下面的批处理文件假定.CSV文件每行仅包含一个字段:存在于特定目录中且具有ANY扩展名的文件的名称(不带扩展名),因此它将该文件复制到另一个目录中。

@echo off
set "theDir=C:\The\Particular\Directory"
for /F "delims=" %%f in (theFile.csv) do (
   copy %theDir%\%%f.* "C:\another\Directory"
)

如果要让图像文件的扩展名来自限制列表,请执行以下操作:

@echo off
set "theDir=C:\The\Particular\Directory"
for /F "delims=" %%f in (theFile.csv) do (
   for %%e in (jpg png) do (
      if exist "%theDir%\%%f.%%e" copy "%theDir%\%%f.%%e" "C:\another\Directory"
)

您可以使用if exist检查文件if exist 所以在你的循环中:

if exist "%%j.jpg" copy "%%j.jpg" target
if exist "%%j.png" copy "%%j.png" target

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM