How to scan a folder and store all file names in a array variable and then loop through the array? -
i new batch , trying following:
- reading or scanning folder
- hold file names in folder in array variable (need hold file name or without extension)
- loop through array , create call specific file/bat based on type of file using if or case statement condition. example: if filename has word person in it, call specific file/bat.
this have far:
@echo off setlocal enabledelayedexpansion rem populate array existent files in folder set i=0 %%b in (*.*) ( set /a i+=1 set list[!i!]=%%b ) set filesx=%i% rem display array elements /l %%i in (1,1,%filesx%) echo !list[%%i]!
... ( echo !list[%%i]! | find /i "person" >nul && call specific.bat !list[%%i]! )
echo !list[%%i]! | find /i "person"
: find word
>nul
: disregard output (we don't need it, errorlevel)
&&
: if previous command successful (the word found), then...
do need array? can "on fly":
for %%b in (*.*) ( echo %%b | find /i "person" >nul && call specific.bat "%%b" )
for filename only, use %%~nb
, full name (including path), use %%~fb
(see for /?
more options)
Comments
Post a Comment