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

Author Topic: batch for run all bat files  (Read 13970 times)

0 Members and 1 Guest are viewing this topic.

Blisk

    Topic Starter


    Intermediate

    Thanked: 1
    • Experience: Familiar
    • OS: Windows 7
    batch for run all bat files
    « on: April 25, 2014, 03:23:56 AM »
    I have to try to run all batch files under folder subfolder wih one batch
    I tried this bot not working
    for /d /r %%i in (D:\myfloder\Drivers\conf\) do if exist "%%i\copylog.bat" start /wait call "%%i\copylog.bat"

    bat file which must be runed is under D:\myfloder\Drivers\conf\MIKE\archive\bat

    I tried to run batch files from other topic

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: batch for run all bat files
    « Reply #1 on: April 25, 2014, 03:47:15 AM »
    This will launch each batch file in that folder:

    Code: [Select]
    @echo off
    cd /d "D:\myfloder\Drivers\conf"
    for %%a in (*.bat) do call "%%a"
    pause

    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: batch for run all bat files
    « Reply #2 on: April 25, 2014, 07:42:14 AM »
    Just make sure foxidrive's file isn't in D:\myflder\Drivers\conf or you will enter an infinite loop. Here is a workaround.

    Code: [Select]
    @echo off
    cd /d "D:\myfloder\Drivers\conf"
    for /f "delims=" %%A in ('dir /b *.bat ^| find /v "%~nx0"') do echo call "%%A"
    echo.
    echo All done.
    pause

    Proof of concept:
    Code: (code) [Select]
    @echo off

    echo Before:
    echo %time%
    for %%a in (*.bat) do echo call "%%a"
    echo %time%
    echo.

    echo After:
    echo %time%
    for /f "delims=" %%A in ('dir /b *.bat ^| find /v "%~nx0"') do echo call "%%A"
    echo %time%
    echo.

    echo All done.
    pause>nul
    Code: (output) [Select]
    T:\>findAllBat
    Before:
     9:43:12.28
    call "colorsd.bat"
    call "colorText.bat"
    call "countLines.bat"
    call "findAllBat.bat"
    call "note.bat"
    call "realtime.bat"
    call "snakeV1.bat"
    call "spaces.bat"
    call "test.bat"
     9:43:12.29

    After:
     9:43:12.30
    call "colorsd.bat"
    call "colorText.bat"
    call "countLines.bat"
    call "note.bat"
    call "realtime.bat"
    call "snakeV1.bat"
    call "spaces.bat"
    call "test.bat"
     9:43:12.37

    All done.
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.

    Blisk

      Topic Starter


      Intermediate

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: batch for run all bat files
      « Reply #3 on: April 25, 2014, 01:07:15 PM »
      lemonilla thanks but not working.
      file not found

      Blisk

        Topic Starter


        Intermediate

        Thanked: 1
        • Experience: Familiar
        • OS: Windows 7
        Re: batch for run all bat files
        « Reply #4 on: April 25, 2014, 01:10:44 PM »
        This will launch each batch file in that folder:

        Code: [Select]
        @echo off
        cd /d "D:\myfloder\Drivers\conf"
        for %%a in (*.bat) do call "%%a"
        pause

        here nothing happends

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: batch for run all bat files
        « Reply #5 on: April 25, 2014, 01:26:26 PM »
        Are your batch files in this folder: D:\myfloder\Drivers\conf

        Blisk

          Topic Starter


          Intermediate

          Thanked: 1
          • Experience: Familiar
          • OS: Windows 7
          Re: batch for run all bat files
          « Reply #6 on: April 25, 2014, 01:36:28 PM »
          Are your batch files in this folder: D:\myfloder\Drivers\conf

          no there must be batch which runs all batch files

          batch files are under
           D:\myfloder\Drivers\conf\MIKE\archive\bat

          but all folders are diferend because are from differend usernames, this one is for MIKE.
          and there is 30 users and 30 folders which have 30 batch files which needs to be runned

          patio

          • Moderator


          • Genius
          • Maud' Dib
          • Thanked: 1769
            • Yes
          • Experience: Beginner
          • OS: Windows 7
          Re: batch for run all bat files
          « Reply #7 on: April 25, 2014, 01:38:40 PM »
           :P
          " Anyone who goes to a psychiatrist should have his head examined. "

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          Re: batch for run all bat files
          « Reply #8 on: April 25, 2014, 01:43:00 PM »
          no there must be batch which runs all batch files

          batch files are under
           D:\myfloder\Drivers\conf\MIKE\archive\bat

          but all folders are diferend because are from differend usernames, this one is for MIKE.
          and there is 30 users and 30 folders which have 30 batch files which needs to be runned
          Then you got your first code example completely backwards as your code is looking for all the batch files in that folder.
          D:\myfloder\Drivers\conf\)

          Squashman



            Specialist
          • Thanked: 134
          • Experience: Experienced
          • OS: Other
          Re: batch for run all bat files
          « Reply #9 on: April 25, 2014, 01:51:27 PM »
          Hmm,
          If there are 30 users how are we doing to know which one is logged in for the correct directory path?

          Blisk

            Topic Starter


            Intermediate

            Thanked: 1
            • Experience: Familiar
            • OS: Windows 7
            Re: batch for run all bat files
            « Reply #10 on: April 25, 2014, 01:54:22 PM »
            Hmm,
            If there are 30 users how are we doing to know which one is logged in for the correct directory path?

            this is runned on server

            and I need to run this batch files
            Code: [Select]
            @echo off
            pushd "..\logfiles"
            for /f "delims=" %%a in ('dir /b /od /a-d ') do set "lastest_file=%%a"
            copy "%lastest_file%" "..\test\new"
            popd

            Squashman



              Specialist
            • Thanked: 134
            • Experience: Experienced
            • OS: Other
            Re: batch for run all bat files
            « Reply #11 on: April 25, 2014, 01:56:30 PM »
            "Runned is not a word."
            Does your browser not have spell check.

            Nor does your reply answer my question.

            Blisk

              Topic Starter


              Intermediate

              Thanked: 1
              • Experience: Familiar
              • OS: Windows 7
              Re: batch for run all bat files
              « Reply #12 on: April 25, 2014, 02:02:30 PM »
              "Runned is not a word."
              Does your browser not have spell check.

              Nor does your reply answer my question.

              Don't know what you mean with user logged on?
              Because it is not relevant for this batch files.

              We need to search copy.bat files in subfolders
               D:\myfloder\Drivers\conf

              and after that script will find copy.bat under

               D:\myfloder\Drivers\conf\MIKE\archive\bat
               D:\myfloder\Drivers\conf\JOE\archive\bat
               D:\myfloder\Drivers\conf\NIKE\archive\bat

              and it will run that copy.bat files

              Squashman



                Specialist
              • Thanked: 134
              • Experience: Experienced
              • OS: Other
              Re: batch for run all bat files
              « Reply #13 on: April 25, 2014, 02:09:59 PM »
              So you said 30 folders with 30 batch files.  That is 900 batch files.  You really want to execute 900 batch files?

              Squashman



                Specialist
              • Thanked: 134
              • Experience: Experienced
              • OS: Other
              Re: batch for run all bat files
              « Reply #14 on: April 25, 2014, 02:13:54 PM »
              I have no idea what you are trying to accomplish.  But this is my take on it.
              Code: [Select]
              for /d %%G in (D:\myfloder\Drivers\conf\*) do (
              FOR %%H in ("%%G\archive\bat\*.bat") do call "%%H"
              )