.bat file not working properly, want to keep leading zero -


this question has answer here:

i getting invalid number.numeric constants either decimal(17),hexadecimal(0x11),or octal(021). keeps renaming 20161201_2012312016 though running when should 20160801_20160831. i've pasted code. thanks

@echo off  set firstday=01  set /a month=%date:~4,2%-1 set month=0%month% set month=%month:~-2%  set year=%date:~10,4%  if %month%==00 (   set month=12   set /a year=%year%-1 )  if %month%==01 set "lastday=31" & goto foundate if %month%==02 set "lastday=28" & goto foundate if %month%==03 set "lastday=31" & goto foundate if %month%==04 set "lastday=30" & goto foundate if %month%==05 set "lastday=31" & goto foundate if %month%==06 set "lastday=30" & goto foundate if %month%==07 set "lastday=31" & goto foundate if %month%==08 set "lastday=31" & goto foundate if %month%==09 set "lastday=30" & goto foundate if %month%==10 set "lastday=31" & goto foundate if %month%==11 set "lastday=30" & goto foundate if %month%==12 set "lastday=31" & goto foundate    :foundate echo year is: %year% echo month is: %month% echo first day of month is: %firstday% echo last day of month is: %lastday%  set filedir=z:\"epiccare reports"\reports_team\scheduled_reports_output \preuhc\   set fileext=.txt set ifile=cpt_000318_ set ofile=%ifile%%year%%month%%firstday%_%year%%month%%lastday%%fileext%  echo output filename: %ofile% ren %filedir%%ifile%.txt %ofile%     move /y %filedir%%ofile% z:\"epiccare reports"\reports_team\scheduled_reports_output\uhc\ 

problem leading zeros, interpreted try perform calculations:

set month=08 set /a month+=1 

will give exact error you're reporting because 08 interpreted octal number, , invalid since 8 cannot octal digit.

fixable in many ways. personal one:

set month=%month:08=8% set month=%month:09=9% set /a month+=1 set month=%month:8=08% set month=%month:9=09% 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -