批量找到文件,复制文件到另一个目录 [英] Batch to find file, copy file to another directory

查看:315
本文介绍了批量找到文件,复制文件到另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是非常相似的发布问题<一href=\"http://stackoverflow.com/questions/5183853/batch-to-find-file-copy-file-then-rename-file-from-a-csv\">here对计算器,但对我不同的是,我需要的批处理脚本执行以下操作


  1. 看其名称只是没了图像扩展,并找到在一个特定的目录
  2. 用该名称图像csv文件
  3. 然后将您的文件,并将其复制到另一个目录

我需要修改什么做此批处理脚本来完成这项任务?

 关闭@echo
 FOR / F令牌= 1,2 = delims,在%%Ĵ(project.csv)做(
   复制%% j.jpgC:\\为MyTestProject \\ newimages
   重命名C:\\为MyTestProject \\ newimages \\ %% j.jpg%% k.jpg
 )


解决方案

下面的批处理文件假设.csv文件包含每行只有一个字段:姓名,没有扩展名,那存在的文件,与任何扩展在一个特定的目录,所以这个文件复制到另一个目录。

 关闭@echo
设置theDir = C:\\中\\特殊\\目录
FOR / Fdelims =%%的(theFile.csv)f执行(
   副本%theDir%\\ %% F *。C:\\其它\\目录

如果你想要的图像文件都从有限的名单采取延期:

 关闭@echo
设置theDir = C:\\中\\特殊\\目录
FOR / Fdelims =%%的(theFile.csv)f执行(
   在(JPG PNG)%% e执行(
      如果存在%theDir%\\ %%˚F%%即复制%theDir%\\ %%˚F%%即C:\\其它\\目录

My question is very similar to the question posted here on stackoverflow but the difference for me is that I need the batch script to do the following

  1. Look at a csv file which has the name only without the image extension and find the image with that name in a particular directory
  2. Then take that file and copy it to another directory

What modifications would I need to do to this batch script to accomplish that task?

 @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 
 )

解决方案

The following Batch file assumes that the .CSV file contains just one field per line: the name, with NO extension, of a file that exist, with ANY extension, in a particular directory, so it copy that file to another directory.

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

If you want the image file have an extension taken from a limited list:

@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"
)

这篇关于批量找到文件,复制文件到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆