Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: FOR command  (Read 2387 times)

0 Members and 1 Guest are viewing this topic.

pleaselogin

    Topic Starter


    Newbie

    FOR command
    « on: February 18, 2010, 12:41:49 AM »
    Hi All!

    Is there a way to ensure that the set of files identified in a FOR command are processed in alphabetical order without explicitly naming each file (in my case, all PDF files)? This list of PDF files changes dynamically.

    FOR %%Z IN (*.pdf) DO <whatever>...

    If I use what I have here, the process picks up any file in the directory, regardless of order.  Maybe there's a way to dynamically dump a list of names for all PDF files within a directory into a variable and then I could pass the variable as the set of files...

    gpl



      Apprentice
    • Thanked: 27
      Re: FOR command
      « Reply #1 on: February 18, 2010, 12:53:08 AM »
      You can process the output of a command, so make the command a sorted directory listing :
      Code: [Select]
      for /f "delims=" %A in ( 'dir /b/on *.pdf' ) do <whatever>... %A

      pleaselogin

        Topic Starter


        Newbie

        Re: FOR command
        « Reply #2 on: February 18, 2010, 07:15:24 PM »
        Thanks, gpl.  I actually got that close, except I forgot the single quotes inside the brackets and couldn't figure it out.