1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using AND (&&)

Discussion in 'Open Forum' started by pb4072, Jul 19, 2011.

  1. pb4072

    Joined:
    Jul 25, 2008
    Messages:
    33
    Likes Received:
    0
    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.
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    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
    
     
  3. pb4072

    Joined:
    Jul 25, 2008
    Messages:
    33
    Likes Received:
    0
    Thanks. Well, yours doesn't work in Windows, but it does run with TC. But, it yields only the list of filenames, no "pdfinfo" data.
     
  4. pb4072

    Joined:
    Jul 25, 2008
    Messages:
    33
    Likes Received:
    0
    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.
     
  5. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    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
     

Share This Page