Quanti Monati
Quanti Monati

Reputation: 811

Batch file: Using of command "FOR" for the appointment of two variables

The question is: how to assign two variables to perform the function?

For example I have something like this:

for %f in *.pdf do PDF2TXT -"%f" -fast -t "%f.txt"

as you can see, %f - is a variable name of every pdf file in the derictory

But I need to include 2 variables something like this:

for %f in *.pdf and for %g in *.rtf do PDF2TXT -"%f" -"%g" -merge -fast -t "%f.txt"

How make it work?

THANKS!

Best regards, Eugene Evtushenko

Upvotes: 0

Views: 49

Answers (1)

Magoo
Magoo

Reputation: 80033

for %f in (*.pdf) do for %g in (%~nf.rtf) do PDF2TXT -"%f" -"%g" -merge -fast -t "%~nf.txt"

FOR syntax is for %x in (list) do

applying the ~n operator to the metavariable (%f in your case) selects just the name part of the filename in %f. See FOR /? |more from the prompt for more info.

You don't say what you mean by "work". It's a meaningless term in this context. We can't read your mind.

This routine will for all .pdf files, select the matching name.rtf and perform PDF2TXT on some combination of whatever the names are, evidently producing name.txt. Without an explicit explanation of what you want to do, we have to assume - that's very dangerous.

It would probably be easier to try

for %f in (*.pdf) do PDF2TXT -"%f" -"%~nf,rtf" -merge -fast -t "%~nf.txt"

which would do the same thing.

Upvotes: 1

Related Questions