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

Author Topic: How to combine forfiles and for loop script to run the file  (Read 19251 times)

0 Members and 1 Guest are viewing this topic.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: How to combine forfiles and for loop script to run the file
« Reply #30 on: November 05, 2014, 08:52:47 AM »
There is a "system cannot find the path specified above". Here is how I set my path.

@echo off
set in_path=E:\input\
set out_path=E:\output

set temp_path=%out_path%\temp\
set processed_files_path=E:\processed files\
md "%processed_files_path%" 2>nul
cd /d "%in_path%"

You have changed this in more ways than only changing the paths and I have no confidence that you have not also introduced other changes...


The error message you mentioned is only cosmetic and you can stop it appearing by changing this in two places:
rd "%temp_path%"
to
rd "%temp_path%" 2>nul


patio

  • Moderator


  • Genius
  • Maud' Dib
  • Thanked: 1769
    • Yes
  • Experience: Beginner
  • OS: Windows 7
Re: How to combine forfiles and for loop script to run the file
« Reply #31 on: November 05, 2014, 08:59:30 AM »
I predict 5 pages total for this thread....
" Anyone who goes to a psychiatrist should have his head examined. "

_unknown_

    Topic Starter


    Beginner

    • Experience: Beginner
    • OS: Windows 7
    Re: How to combine forfiles and for loop script to run the file
    « Reply #32 on: November 05, 2014, 09:30:51 PM »
    Lets see the entire batch file that you are using.  Please keep it as is.  Do not obfuscate anything.

    The following are the entire batch file I am using from the input folder:

    A2001274033500.L1_LAC.A.hdf
    A2001274033500.L2_LAC.A.hdf
    A2001274051000.L1_LAC.A.hdf
    A2001274051000.L2_LAC.A.hdf
    A2001274051500.L1_LAC.A.hdf
    A2001274051500.L2_LAC.A.hdf
    A2001274065000.L1_LAC.A.hdf
    A2001274065000.L2_LAC.A.hdf
    A2001275041500.L1_LAC.A.hdf
    A2001275041500.L2_LAC.A.hdf
    A2001275042000.L1_LAC.A.hdf
    A2001275042000.L2_LAC.A.hdf
    A2001275055000.L1_LAC.A.hdf
    A2001275055000.L2_LAC.A.hdf
    A2001275055500.L1_LAC.A.hdf
    A2001275055500.L2_LAC.A.hdf
    A2001275060000.L1_LAC.A.hdf
    A2001275060000.L2_LAC.A.hdf


    While the bat file is running here are the files I've pasted/added to the input folder from the desktop folder.

    A2001038044500.L2_LAC.A.hdf
    A2001038045000.L2_LAC.A.hdf
    A2001038063000.L2_LAC.A.hdf
    A2001038062500.L2_LAC.A.hdf

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: How to combine forfiles and for loop script to run the file
    « Reply #33 on: November 05, 2014, 09:37:43 PM »
    I asked for the BATCH file code you are using!! Not what input files you are using!!!

    _unknown_

      Topic Starter


      Beginner

      • Experience: Beginner
      • OS: Windows 7
      Re: How to combine forfiles and for loop script to run the file
      « Reply #34 on: November 05, 2014, 10:41:53 PM »
      I asked for the BATCH file code you are using!! Not what input files you are using!!!

      Sorry  :(

      @echo off
      set in_path=E:\input\
      set out_path=E:\output\

      set temp_path=%out_path%\temp\
      set processed_files_path=E:\processed files\
      md "%processed_files_path%" 2>nul
      cd /d "%in_path%"

      :loop
      set now=%date% %time%
      if exist "*.L2_LAC.*.hdf" (
         rd "%temp_path%" 2>nul
         if exist "%temp_path%\" echo An ERROR occurred as the "%temp_path%\" folder exists - may

      have unprocessed files within: & pause & goto :EOF
         md "%temp_path%" 2>nul
         echo moving files @ %now%
         move "*.L2_LAC.*.hdf" "%temp_path%" >nul
            cd /d "%temp_path%"
               echo projecting files
               FORFILES /m *L2_LAC*.hdf /C "cmd /c gdalwarp -geoloc -t_srs EPSG:4326 -te 113.205 1.120 157.105 2.005 HDF4_SDS:UNKNOWN:@file:37 %out_path%\@fname.tif"
               move "*.L2_LAC.*.hdf" "%processed_files_path%" >nul
            cd ..
            rd "%temp_path%" 2>nul
            if exist "%temp_path%\" echo An ERROR occurred as the "%temp_path%\" folder exists -

      may have unprocessed files within: & pause & goto
      )

      timeout /t 30 /nobreak
      goto :loop

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: How to combine forfiles and for loop script to run the file
      « Reply #35 on: November 06, 2014, 06:39:06 AM »
      Would it kill you to use bulletin board CODE tags like everyone else has been using.

      You have two lines of code that are wrapping.  If they are like that in your batch file they would cause some syntax errors.

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: How to combine forfiles and for loop script to run the file
      « Reply #36 on: November 06, 2014, 07:23:18 AM »
      There is a "system cannot find the path specified above".

      The error message you mentioned is only cosmetic

      Now that I look again - the error you quoted (without the word "above" in Win 8.1) is caused by a different problem,
      but it would have to be such an elementary error that I can't believe you keep getting it...

      The input folder doesn't exist, and so there can't be any source files in there.
      This assumes that the batch file you pasted above is correct...

      _unknown_

        Topic Starter


        Beginner

        • Experience: Beginner
        • OS: Windows 7
        Re: How to combine forfiles and for loop script to run the file
        « Reply #37 on: November 06, 2014, 07:26:35 PM »
        Would it kill you to use bulletin board CODE tags like everyone else has been using.

        You have two lines of code that are wrapping.  If they are like that in your batch file they would cause some syntax errors.

        Code: [Select]
        @echo off
        set "in_path=E:\input\"
        set "out_path=E:\output"

        set "temp_path=%out_path%\temp\"
        set "processed_files_path=E:\processed files\"
        md "%processed_files_path%" 2>nul
        cd /d "%in_path%"

        :loop
        set now=%date% %time%
        if exist "*.L2_LAC.*.hdf" (
           rd "%temp_path%" 2>nul
           if exist "%temp_path%\" echo An ERROR occurred as the "%temp_path%\" folder exists - may have unprocessed files within: & pause & goto :EOF
           md "%temp_path%" 2>nul
           echo moving files @ %now%
           move "*.L2_LAC.*.hdf" "%temp_path%" >nul
              cd /d "%temp_path%"
                 echo projecting files
                 FORFILES /m *L2_LAC*.hdf /C "cmd /c gdalwarp -geoloc -t_srs EPSG:4326 -te 109.975 3.475 135.025 25.025 HDF4_SDS:UNKNOWN:@file:37 %out_path%\@fname.tif"
                 move "*.L2_LAC.*.hdf" "%processed_files_path%" >nul
              cd ..
              rd "%temp_path%" 2>nul
              if exist "%temp_path%\" echo An ERROR occurred as the "%temp_path%\" folder exists - may have unprocessed files within: & pause & goto
        )

        timeout /t 30 /nobreak
        goto :loop

        _unknown_

          Topic Starter


          Beginner

          • Experience: Beginner
          • OS: Windows 7
          Re: How to combine forfiles and for loop script to run the file
          « Reply #38 on: November 06, 2014, 07:51:36 PM »
          You have changed this in more ways than only changing the paths and I have no confidence that you have not also introduced other changes...


          The error message you mentioned is only cosmetic and you can stop it appearing by changing this in two places:
          rd "%temp_path%"
          to
          rd "%temp_path%" 2>nul

          This solved the error "can't find the path specified above". But after all the files from the input folder was projected successfully and those files were moved to the processed files folder then I've pasted 4 new files in the input folder I don't know why it isn't even working. It just keeps on waiting for 30 seconds  :'( But in your case it's working :'(

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          Re: How to combine forfiles and for loop script to run the file
          « Reply #39 on: November 06, 2014, 08:06:17 PM »
          Because in the middle of the script you do a change directory to the temp path but never do a change directory back to the input path because it is outside the loop label.

          _unknown_

            Topic Starter


            Beginner

            • Experience: Beginner
            • OS: Windows 7
            Re: How to combine forfiles and for loop script to run the file
            « Reply #40 on: November 06, 2014, 09:01:21 PM »
            Code: [Select]
                  cd ..
                  rd "%temp_path%"
                  if exist "%temp_path%\" echo An ERROR occurred as the "%temp_path%\" folder exists - may have unprocessed files within: & pause & goto
            )

            timeout /t 30 /nobreak
            goto :loop

            Figured it out already. The cd .. part is causing the problem. Just modified it by changing the directory pointing to the input_path.
            Thank you squashman and to you foxidrive who do all the efforts in creating this script and for your patience.  :)

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: How to combine forfiles and for loop script to run the file
            « Reply #41 on: November 07, 2014, 04:30:15 AM »
            Because in the middle of the script you do a change directory to the temp path but never do a change directory back to the input path because it is outside the loop label.

            Well spotted Squashman.  My test created extra files after the timeout command but it created them in the current directory, and of course it worked fine.


            Anyway, it's solved after a lengthy battle, nice work.  :)

            _unknown_

              Topic Starter


              Beginner

              • Experience: Beginner
              • OS: Windows 7
              Re: How to combine forfiles and for loop script to run the file
              « Reply #42 on: November 25, 2014, 11:07:43 PM »
              Figured it out already. The cd .. part is causing the problem. Just modified it by changing the directory pointing to the input_path.
              Thank you squashman and to you foxidrive who do all the efforts in creating this script and for your patience.  :)