- 1 year ago
windows batch | for loop and dir command with parameter
Comment
1 / 1
In Windows batch scripting, you can use a for
loop along with the dir
command and a parameter to process files or directories based on the specified parameter. Below is an example of how to achieve this:
batch@echo off
setlocal enabledelayedexpansion
REM Replace "C:\Your\Directory" with the directory path you want to process
set "directory=C:\Your\Directory"
REM Replace ".txt" with the file extension you want to filter
set "fileExtension=.txt"
REM Use a for loop to process the files or directories
for %%F in ("%directory%\*%fileExtension%") do (
REM %%F is the loop variable representing each file or directory with the specified file extension
echo Processing: %%F
REM Add your desired commands here to process the file or directory
REM For example, you can call another script or execute a command using %%F as an argument
)
In this script, you can customize the directory
and fileExtension
variables to specify the directory you want to process and the file extension you want to filter. The for
loop iterates through each file or directory matching the specified file extension, and you can perform the desired operations within the loop using the %%F
loop variable.
Save the script with a .bat
extension, and when you run it, it will process the files or directories based on the provided parameters.