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

Author Topic: Need to process all the files in the folder using DOS?  (Read 3000 times)

0 Members and 1 Guest are viewing this topic.

vinoth124

    Topic Starter


    Rookie

    Need to process all the files in the folder using DOS?
    « on: December 16, 2008, 04:11:24 AM »
    Hi Friend,

    Actually I need to process all the files from a folder as one by one...., Let me explain the scenerio in detail....

    For example a Folder "collection" contains several number of file (vary to time). I need to process all the available files (one by one). Process in the sense I will be validating certain things and I will save it in some other location.

    Is there is any way to recolve this issue in DOS? If so will you please help me to trigger out the same....,

    Thanks,
    Vinoth R :)

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Need to process all the files in the folder using DOS?
    « Reply #1 on: December 16, 2008, 05:20:01 AM »
    We have done this countless times. I'm very surprised that your site search didn't turn up anything  ;)

    Code: [Select]
    for /f "tokens=* delims=" %%v in ('dir /a:-d  "c:\collection"') do (
    .
    . Your code goes here
    .
    )

    There are many variants of the for instruction. We would need more specifics to give you a definitive answer.

    Good luck.  8)

    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    vinoth124

      Topic Starter


      Rookie

      Re: Need to process all the files in the folder using DOS?
      « Reply #2 on: December 22, 2008, 12:22:05 AM »
      Hi Friend,

      With reference to your above suggestion...., How I can fetch the first file in the directory (In first execution) and fetch second file (In second excecution)....., Where the files name will be stored....,


      Thanks
      Vinoth

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Need to process all the files in the folder using DOS?
      « Reply #3 on: December 22, 2008, 04:47:09 AM »
      I may have been a bit hasty in posting the code. I left out a switch on the dir command:

      Code: [Select]
      for /f "tokens=* delims=" %%v in ('dir /a:-d  /b "c:\collection"') do (
      .
      . Your code goes here
      .
      )

      The file name is stored in the %%v variable. With each iteration of the loop, the %%v variable takes on a new value. The for loop is self contained and will end when there are no new values for %%v to process (in this case, when there are no more files in the dir listing).

      Code: [Select]
      for /f "tokens=* delims=" %%v in ('dir /a:-d  /b "c:\collection"') do (
          echo %%v
      )

      Check out the dir command, there are switches you may find helpful.

      Good luck.  8)
      « Last Edit: December 22, 2008, 06:49:54 AM by Sidewinder »
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein