loops - Windows Batch counter with follow '0' -


this question has answer here:

hi working on small batch files makes rename files in directory, far loop working make 0 infront of counter result this:

setlocal enabledelayedexpansion  set /a counter=0  %%a in (*.txt) (     set /a counter+=1      copy "%%a" "directory/%%a.!counter!.txt"     ) 

this outputs as:

     tvscriptmonday.txt => tvscriptmonday.1.txt     tvscripttuesday.txt => tvscripttuesday.2.txt 

but have output:

    tvscriptmonday.01.txt     tvscripttuesday.02.txt 

i tried using if command:

if !counter! <9 set counter=0!counter! 

but somehow not work, ideas anyone?

using little trick:

setlocal enabledelayedexpansion  set /a counter=100  %%a in (*.txt) (     set /a counter+=1      copy "%%a" "directory/%%a.!counter:~-2!.txt" ) 

the :~-2 takes last 2 chars counter only.

expandable: example, if need 4 number scheme, start counting 10000 , extract last 4 chars :~-4


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -