简体   繁体   中英

Windows batch command: multiple folders

Following Windows batch command converts all tif images in the folder C:\\RootFolder\\Folder1.

for %%i in (C:\RootFolder\Folder1\*.tif) do "Tiff2Pdf.exe" -o C:\RootFolder\Folder1\%%~ni.pdf %%i

How can I do it for all the folders available in RootFolder?

RootFolder
  -Folder1
  -Folder2
  -Folder3
   .
   .

Thanks for your time

There's another way - just to add it:

@echo off
for /r "c:\rootfolder\folder1" %%a in (*.tif) do "Tiff2Pdf.exe" -o "%%~dpna.pdf" "%%a"

I also changed the loop variable to a because i is close to l and I and 1 in many fonts.

FOR /F "delims=" %%i IN ('dir /b /s C:\RootFolder\Folder1\*.tif') DO "Tiff2Pdf.exe" -o "%%~dpi%%~ni.pdf" "%%i"
  • Use dir /s /b to do a full recursive enumeration
  • Use FOR /F "delims=" to parse the results and handle paths with spaces.
  • Use the %%~dpi%% to get the directory of each file.
  • Use %%~ni to get the file's name with out an extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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