batch file to execute a command on all files in mu

2019-06-04 02:46发布

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.

1条回答
相关推荐>>
2楼-- · 2019-06-04 03:01
@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
查看更多
登录 后发表回答