Do things with file array in directory

This will print exe file-names in directory where batch file is having a good time
for /f "delims=" %%f in ('dir /b "%~dp0*.exe"') DO echo %%f
This will print full path
for /f "delims=" %%f in ('dir /b "%~dp0*.exe"') DO (
echo %~dp0%%f
)
If you want to pass /S switch you have to append %~dp0 and use quotes
for /f "delims=" %%f in ('dir /b "%~dp0*.exe"') DO (
"%~dp0%%f" /S
)
For patch install
for /f "delims=" %%f in ('dir /b "%~dp0*.msp"') DO (
msiexec /update "%~dp0%%f" /qn
)
For patch install from network path
for /f "delims=" %%f in ('dir /b "%~dp0*.msp"') DO (
%systemroot%\system32\msiexec.exe /update "%~dp0%%f" /qn
)
For most flexible install it is recommended to use variable
set src=%~dp0
for /f "delims=" %%f in ('dir /b "%src%*.msp"') DO (
%systemroot%\system32\msiexec.exe /update "%src%%%f" /qn
)

No comments: