batch file - Create folder with version and date -
first question here. i've used batch files automating lot of action 1 getting difficult.
imagine have folder (lets phone call 'projectfolder') , have folders within project folder (lets phone call them 'data', 'tools, 'trash') , each of these folders have files. want create within 'projectfolder' 'backup' folder , within 1 folder called 'v001_date_time_user' , re-create folders 'data' , 'tools' within folder. run script 1 time again create new version , creates 'v002_date_time_user' , copies same 'data' , 'tools' folders , files again.
what can create folder called 'v_date_time_user' within 'backup' folder have no thought how create version part 3 digits.
this code now:
@echo off & setlocal enableextensions :: variables set datentime="[%date:~6,6%-%date:~3,2%-%date:~0,2%]_[%time:~0,2%-%time:~3,2%]" set backup="backup" set /a version=000 set backupcmd=xcopy /s /c /d /e /h /i /r /k /y :: check existence of [backup] :: if [backup] doesn't exist, create if not exist "%backup%\" ( echo folder "%backup%" not found echo creating folder "%backup%" md "%backup%" ) :: create version folder version number_date_hour_user md "%backup%\v%version%_%datentime%_[%username%]" :: re-create older version newer version xcopy "data" "%backup%\v%version%_%datentime%_[%username%]\data" /e /c /i /h /q xcopy "tools" "%backup%\v%version%_%datentime%_[%username%]\tools" /e /c /i /h /q
can help? luís
there couple of ways can think of. loop through every folder origin v , number, , count them. if you're starting 000 number of matches next number.
@echo off setlocal enabledelayedexpansion :: if you're starting 001 rather 000, set count=1 instead of 0 here. set count=0 pushd "path\to\projectfolder\backup" /f %%i in ('dir /b v* ^| findstr "^v[0-9][0-9][0-9]"') set /a count=!count!+1 popd set count=00%count% set count=%count:~-3%
then %count%
next number.
another way loop through dir /b /o:n
(alphabetic sorting) , capture lastly directory name, presumably v### highest number. grab first 4 characters of capture , chop off v.
batch-file
No comments:
Post a Comment