15060

batch file to execute a command on all files in multiple directories

Question:

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.

Answer1:

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

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

Recommend

  • Jquery toggle on custom animation
  • Calculate Sum From Moving 4 Rows in SQL
  • Can't add admin in Shield Elasticsearch - [Error]Could not find or load main class org.elastics
  • Get around 3rd party cyclic dll dependencies?
  • Cas Ticket Issue in Jmeter
  • Interrupting a thread in Java
  • What else can I do to troubleshoot a package not importing in python yet imports in ipython while in
  • waf cannot find an existing library
  • TinyMCE-dialogs of Plone site are not translated
  • Setting Nsight to run with existing Makefile project
  • Is it possible to retrieve an extended or full query history in google bigquery?
  • Is it OK to write code after [super dealloc]?
  • Excel VBA Delete Row If Misspelled Word
  • Avoiding try/catch hell in my web pages
  • No System image available when adding AVD in Android studio
  • Batch file to delete all folders in a directory except the newest folder
  • How is user.dir configured for Tomcat servlets?
  • Errno 2 using python shutil.py No such file or directory for file destination
  • How to import Navit into Eclipse and use it in own android project
  • Xamarin iOS debugger not hitting breakpoints
  • Git cleanup/garbage collection on remote VSO git repository
  • Visual Studio - PathTooLongException even when the path length is less than 260 characters
  • 'doc_del_count' bigger than 'doc_count' on CouchDB
  • c# winform DrawToBitmap offscreen
  • Changing Jupyter Notebook start up folder by modifying “start in” not working any more
  • WPF Visiblity Binding to Boolean Expression with multiple Variables
  • Conversion from string “a” to type 'Boolean' is not valid
  • Paperclip, set path outside of rails root folder
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Arrays break string types in Julia
  • Is there a mandatory requirement to switch app.yaml?
  • Use group_by to filter specific cases while keeping NAs
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Append folder name and increment by 1 using batch script
  • Busy indicator not showing up in wpf window [duplicate]