Reputation: 1127
I need to execute some command in each of the folder from the given list if it (folder) exists.
What wrong with this script?
@echo off
set FILE_LIST=(a b c d file)
for %%i in %FILE_LIST% do (
IF EXIST %cd%\%%~i (
set flag=Yes
) else (
set flag=No
)
:: Just for problem illustration, for SO
echo "%%i": %flag%
if %flag%=="Yes" (
start somecommand %cd%\%%~i\program.exe
)
)
Result of execution:
C:\Temp>script.bat
"a": No
"b": No
"c": No
"d": No
"file": No
Folder content:
Upvotes: 0
Views: 39
Reputation:
You might be overcomplicating this a bit, why not just do:
@echo off
for %%i in (a b c d file) do if exist "%%i" echo "%%i"
so if you wanted to run a program, then just do:
@echo off
for %%i in (a b c d file) do if exist "%%i" start "somecmd" "%%i\program.exe"
Upvotes: 3