How to batch convert all TIFF files in a folder and all sub folders to PDF files?

Please help, I am trying to craft a command line command for img2pdf.exe to convert all TIF files in a folder and all subfolders to PDF format. I found this in a blog post, but I can't get it to run. No errors, no verbose of any kind, just nothing:

for /r x:\images\folder001 %F in (*.tif) do "C:\VeryPDF\img2pdf.exe" -o "%~dpnF.pdf" "%F"

What am I doing wrong?

Thank you.
Customer
--------------------------------------------
Your command line is no problem,

for /r x:\images\folder001 %F in (*.tif) do "C:\VeryPDF\img2pdf.exe" -o "%~dpnF.pdf" "%F"

image

However, if you wish execute above command line from a .bat file, you need use %% to instead of %, for example,

for /r x:\images\folder001 %%F in (*.tif) do "C:\VeryPDF\img2pdf.exe" -o "%%~dpnF.pdf" "%%F"

You may look at following details to understand more information about "for /r" command line option,

FOR /R

Loop through files (Recurse subfolders)

Syntax
      FOR /R [[drive:]path] %%parameter IN (set) DO command

Key
   drive:path  : The folder tree where the files are located.

   set         : A set of one or more files enclosed in parentheses (file1.*, another?.log).
                 Wildcards must be used.
                 If (set) is a period character (.) then FOR will loop through every folder.

   command     : The command to carry out, including any parameters.
                 This can be a single command, or if you enclose it
                 in (parentheses), several commands, one per line.

   %%parameter : A replaceable parameter:
                 in a batch file use %%G (on the command line %G)
This command walks down the folder tree starting at [drive:]path, and executes the DO statement against each matching file.

If the [drive:]path are not specified they will default to the current drive:path.

FOR parameters (%%A – %%Z)
Read the main FOR introduction page for a full description of assigning the replaceable %%parameter.
FOR parameters are used in all variations of the FOR command, it is a good idea to get up to speed with writing a basic FOR command before trying the more complex FOR / R variant.

Unlike some other variants of the FOR command, with FOR /R you must include a wildcard (either * or ?) in the 'set' to get consistent results returned. In many cases you can work around this by adding a single character wildcard e.g. if you are looping through multiple folders to find the exact filename myfile.txt you could instead specify myfile.t?t

FOR does not, by itself, set or clear the Errorlevel.

FOR is an internal command.

Examples

List every .bak file in every subfolder starting at C:\temp\
For /R C:\temp\ %%G IN (*.bak) do Echo "%%G"

A batch file to rename all .LOG files to .TXT in the 'demo' folder and all sub-folders:
For /R C:\demo\ %%G in (*.LOG) do Echo REN "%%G" "%%~nG.TXT"

Alternatively the same thing using the current directory:
CD C:\demo\
For /R %%G in (*.LOG) do Echo REN "%%G" "%%~nG.TXT"

(Remove the Echo from these commands to run them for real.)

Change directory to each subfolder under C:\Work in turn:

FOR /R "C:\Work\" %%G in (.) DO (
Pushd %%G
Echo now in %%G
Popd )
Echo "back home"

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!