Batch file increment folder number -
i'm trying create batch file creates folders 1.2.0.1, 1.2.0.2,1.2.0.3, etc. fould code previous question , works needs:
@echo off setlocal enabledelayedexpansion set "basename=new_folder" set "n=0" /f "delims=" %%f in ( '2^>nul dir /b /ad "%basename%*."^|findstr /xri "%basename%[0-9]*"' ) ( set "name=%%f" set "name=!name:*%basename%=!" if !name! gtr !n! set "n=!name!" ) set /a n+=1 md "%basename%%n%"
so way attempted have 2 variables, 1 holds first 3 digits 2.4.0 , other holds forth one.
set version=1.2.0 cd c:\users\build set "lastfolder=0" /f "delims=" %%f in ( '2^>nul dir /b /ad "%version%*."^|findstr /xri "%version%[0-9]*"' ) ( set "name=%%f" set "name=!name:*%version%=!" if !name! gtr !lastfolder! set "lastfolder=!name!" ) set /a nextfolder=lastfolder+1 md "%version%.%nextfolder%"
but doesn't work because it's creating first folder , not ones following. can me determine issue? thanks
this create folders, if exist or not.
@echo off /l %%a in (1,1,255) md "1.2.0.%%a" 2>nul
this should create next folder in series:
@echo off cd c:\users\build /l %%a in (1,1,20000000) if not exist "1.2.0.%%a\" md "1.2.0.%%a" & goto :done :done
this code works - , same code above, within reason. 2 million folders seems fair number, if takes few seconds. :)
@echo off setlocal enabledelayedexpansion set version=1.2.0. cd c:\users\build set "lastfolder=0" /f "delims=" %%f in ( '2^>nul dir /b /ad "%version%*."^|findstr /xri "%version%[0-9]*"' ) ( set "name=%%f" set "name=!name:*%version%=!" if !name! gtr !lastfolder! set "lastfolder=!name!" ) set /a nextfolder=lastfolder+1 md "%version%%nextfolder%" pause
Comments
Post a Comment