Using AND (&&)

Hi,
I'm trying to use a simple && (AND) sequence. I've tried it in both Windows command line and TC. Here it is:

for %I in (*.pdf) do echo %I >> files.txt && pdfinfo %I >> files.txt

I want to write to a file the name of the PDF file I'm working on. Then, underneath that echoed line in the text file, I want to run a simple PDF utility that I use to interrogate the PDF for page count, etc.

All I'm getting is a text file with the names of the files, but, no PDF information. I know that the "pdfinfo" command is in my path because, as it's running this sequence, I see its nomenclature flying by.

I'm getting the same results with both Windows and TC.

Thanks.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,957
53
Albuquerque, NM
prospero.unm.edu
Hi,
I'm trying to use a simple && (AND) sequence. I've tried it in both Windows command line and TC. Here it is:

for %I in (*.pdf) do echo %I >> files.txt && pdfinfo %I >> files.txt

I want to write to a file the name of the PDF file I'm working on. Then, underneath that echoed line in the text file, I want to run a simple PDF utility that I use to interrogate the PDF for page count, etc.

All I'm getting is a text file with the names of the files, but, no PDF information. I know that the "pdfinfo" command is in my path because, as it's running this sequence, I see its nomenclature flying by.

I'm getting the same results with both Windows and TC.
I'm not sure why you're using the conditional && -- perhaps you just want a command separator there?

Code:
for %I in (*.pdf) ( echo %I & pdfinfo %I ) >> files.txt
 
I got it. I've got spacebands in my PDF filenames, so, I have to put quotes around my file variable.

for %I in ("*.pdf") ( echo "%I" & pdfinfo "%I" ) >> files.txt

Thanks a lot for your help. You guided me.
 
May 20, 2008
3,515
3
Elkridge, MD, USA
pb4072 wrote:
| I got it. I've got spacebands in my PDF filenames, so, I have to put
| quotes around my file variable.
|
| for %I in ("*.pdf") ( echo "%I" & pdfinfo "%I" ) >> files.txt

Notes:
1/ You do not need to quote the wild-card search expression unless it
contains whitespace etc.
2/ If you use the "noclobber" feature, a strong deterrent to accidental
overwriting, you need to create you output file explicitly, UNLESS
3/ You can make a single command group of the whole FOR like this:

( for %I in (*.pdf) ( echo "%I" & pdfinfo "%I" ) ) > files.txt

--
HTH, Steve