- 1 year ago
Run batch script on all files in a folder
Comment
1 / 1
To run a batch script on all files in a folder, you can use a for
loop in the Windows command prompt. Here's an example:
batch@echo off
setlocal
set "folder=C:\path\to\folder"
set "script=your_script.bat"
for %%F in ("%folder%\*") do (
if %%~xF==.txt (
echo Processing file: %%F
call "%script%" "%%F"
)
)
endlocal
In the above example, replace C:\path\to\folder
with the actual path to the folder containing the files you want to process. Replace your_script.bat
with the name of your batch script.
The for
loop iterates over all files in the specified folder. Modify the if
statement condition (%%~xF==.txt
in this example) to match the criteria for selecting the files you want to process. Inside the loop, you can perform any desired actions on each file, such as calling your batch script using the call
command.
Save the above code as a .bat
file, and then run the batch script to process all the files in the specified folder.