@ECHO OFF
SETLOCAL EnableExtensions
set "_params=%*"
if not defined _params (
echo %~nx0: nothing to do
pause
exit /B
)
set "_params=%_params:,=","%"
for %%G in ("%_params%") do (
echo dir "%%~G"
)
Output
==> 37321331.bat
37321331.bat: nothing to do
Press any key to continue . . .
==> 37321331.bat C:\Program Files,C:\temp,C:\John Snow
dir "C:\Program Files"
dir "C:\temp"
dir "C:\John Snow"
==>
Above script requires some elaborating: it would fail if some argument is enclosed in a pair of double quotes:
==> 37321331.bat C:\Program Files,C:\temp,"C:\John Snow"
dir "C:\Program Files"
dir "C:\temp"
dir ""C:\John"
dir "Snow"""
Edit. Use next code snippet to fix it: set "_params=%_params:"=%" would remove all " double quotes from supplied string.
set "_params=%_params:"=%"
set "_params=%_params:,=","%"
for %%G in ("%_params%") do (
echo dir "%%~G"
)
Resources (required reading, incomplete):
script.bator you want to call script .bat with each of the items?for /fcommand giving "," as delimiter. Check here.