batch file - For loops and reading folder names from a directory -
i have directory various folders archive based on user input in batch file. folder [project backups] has various projects [pjt001, pjt002, pjt003] may vary time time. first thing did set variable based on input user , use variable in command 7zip archive in particular location. fine requesting backup 1 project @ time, if user wanted backup multiple projects in 1 go. tried create loop if user entered multiple projects when asked [pjt001 pjt003 pjt005] had no luck. please see below tried.
set /p project= projects backup? !user may enter [pjt001 pjt003 pjt005] /f "tokens=* delims= " %%g in ("%project%") ( %appliction% -t7z -mx9 -mmt "%destination%\%%g" %source%\%%g )
any suggestions on failing? i'm able archive first project in scenario.
the second thing like user able imput "all" , projects in directory archived. possible batch file read of folder names in directory , store in variable, can break down tokens , create loop before (but works ha!) projects archived? better solutions welcomed too!
many thanks!
there many flavors of for, , need make sure using correct one.
in case believe want use simple (not /f):
set /p project= projects backup? %%g in (%project%) %appliction% -t7z -mx9 -mmt "%destination%\%%g" "%source%\%%g"
if want interpret all
projects (folders), /d iterate folders:
set /p project= projects backup? if /i "%project%" equ "all" ( /d %%g in ("%source%\*") %appliction% -t7z -mx9 -mmt "%destination%\%%~nxg" "%%g" else ( %%g in (%project%) %appliction% -t7z -mx9 -mmt "%destination%\%%g" "%source%\%%g" )
Comments
Post a Comment