Skip to content

Instantly share code, notes, and snippets.

@joshuatz
Last active January 11, 2022 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuatz/6bd2cfe8b0661937075b9aeddee57788 to your computer and use it in GitHub Desktop.
Save joshuatz/6bd2cfe8b0661937075b9aeddee57788 to your computer and use it in GitHub Desktop.
Bulk Folder Runner - Batch Script

If you want to run this and capture the results to a log file, you should make sure to also capture stderr. You can use something like:

./bulk_folder_runner.bat > log.txt 2>&1

If running via Task Scheduler, please note that Task Scheduler does not properly record exit error codes.

@echo off
@REM # Have the below variable point to a plain text file that contains a list of folder that this script should run `node index.js` in, separated by line breaks
@REM # The folder paths can be relateive or absolute paths
SET FOLDERS_LIST_FILE=.\folders.txt
@REM # Set this to 1 if you want this script to stop completely if any run of `index.js` fails (throws exception)
SET STOP_ON_ERROR=0
SET START_DIR="%cd%"
for /f "tokens=*" %%p in (%FOLDERS_LIST_FILE%) do (
cd %%p
@REM # The command to run in each folder
node index.js && (
echo "Successful execution in %%p"
) || (
echo "Failed in %%p, see error above"
if %STOP_ON_ERROR% neq 0 (
exit /b !errorlevel!
)
)
cd %START_DIR%
)
echo "Done!"
.\folder-a
.\folder-b
C:\dev\scheduled-tasks\folder-c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment