批处理文件来在多个目录中的所有文件,执行命令 [英] batch file to execute a command on all files in multiple directories

查看:560
本文介绍了批处理文件来在多个目录中的所有文件,执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使运行此命令的批处理文件:

  C:\\ Program Files文件(x86)的\\ IrfanView的\\ i_view32.exeC:\\用户\\ digi_admin \\ TIFF格式\\
。旧目录\\ *。TIF/ INI =C:\\用户\\ digi_admin \\文件\\/ advancedbatch / TIFC = 4
/转换=C:\\用户\\ digi_admin \\ CompTIFs \\某个文件夹\\新目录\\ *。TIF

在几个文件夹中的所有文件。所有文件将位于\\ TIFF格式\\但将驻留在几个不同的子文件夹。 (旧目录)此外,我需要创建文件夹\\新目录\\(这将具有相同的名称作为旧目录)命令之前运行(运行?)。以下是我迄今为止:

  FOR / D%D IN(C:\\用户\\ digi_admin \\ TIFF格式\\ *。*)做C:\\ Program Files文件
(86)\\ IrfanView的\\ i_view32.exe%d个\\ * TIF / INI =C:\\用户\\ digi_admin \\文件\\
/ advancedbatch / TIFC = 4 /转换=C:\\用户\\ digi_admin \\ CompTIFs \\某个文件夹\\%d个\\ *。TIF。

我在命令行一直试图这么%D应该%%Ð。我不熟悉DOS,所以我敢肯定,这是比较简单的。任何帮助将大大AP preciated。


解决方案

  @ECHO OFF
SETLOCAL
SET destroot = C:\\用户\\ digi_admin \\ CompTIFs
FOR / D %% D IN(%destroot%\\ *)DO(
MD%destroot%\\ %%〜NXD2 - ; NULC:\\ Program Files文件(x86)的\\ IrfanView的\\ i_view32.exe%%Ð\\ *。TIF/ INI =C:\\用户\\ digi_admin \\文件\\/ advancedbatch / TIFC = 4 /转换=% destroot%\\ %%〜NXD \\ *。TIF

现在 - 这是假设/转换'是一个目的地文件规范

注:


  • 我给自己定目标根到一个变量 - 使打字
    容易

  • 2> NUL燮presses生成错误消息的应
    目标目录已经存在

  • %%〜NXD指从%% D中的名和扩展名。在所有的可能性中,
    扩展将不存在 - 这是无害的

I would like to make a batch file that runs this command:

C:\Program Files (x86)\IrfanView\i_view32.exe" "C:\Users\digi_admin\TIFFs\
OLD DIRECTORY\*.tif" /ini="C:\Users\digi_admin\Documents\" /advancedbatch /tifc=4  
/convert="C:\Users\digi_admin\CompTIFs\Some Folder\NEW DIRECTORY\*.tif"

On all the files in several folders. All the files will be located in \TIFFs\ but will reside in several different sub-folders. (OLD DIRECTORY) Also I need to create the folder \NEW DIRECTORY\ (which will have the same name as OLD DIRECTORY) before the command is ran (is run?). Here is what I have so far:

FOR /D %d IN ("C:\Users\digi_admin\TIFFs\*.*") DO "C:\Program Files 
(x86)\IrfanView\i_view32.exe" %d\*.tif /ini="C:\Users\digi_admin\Documents\" 
/advancedbatch /tifc=4 /convert="C:\Users\digi_admin\CompTIFs\Some Folder\%d\*.tif"

I have been trying it in command line so %d should be %%d. I am unfamiliar with DOS so I'm sure it is relatively simple. Any help would be greatly appreciated.

解决方案

@ECHO OFF
SETLOCAL
SET destroot=C:\Users\digi_admin\CompTIFs
FOR /D %%d IN ("%destroot%\*") DO (
MD "%destroot%\%%~nxd" 2>nul

"C:\Program Files (x86)\IrfanView\i_view32.exe" "%%d\*.tif" /ini="C:\Users\digi_admin\Documents\" /advancedbatch /tifc=4 /convert="%destroot%\%%~nxd\*.tif"
)

Now - that's assuming the '/convert' is a destination filespec.

Notes:

  • I've set the destination root into a variable - makes the typing easier
  • the 2>nul suppresses the error message generated should the destination directory already exist
  • %%~nxd means the Name and eXtension from %%d. In all probability, the extension won't exist - this is harmless

这篇关于批处理文件来在多个目录中的所有文件,执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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