How to create date name of log file in batch?

March 19, 2013 at 21:56:00
Specs: Windows 7
20130101.log
20130102.log
..................
..................
..................
20130301.log
20130302.log
...................
...................
20131230.log
20131231.log

how to create this log files


See More: How to create date name of log file in batch?

Report •


#1
March 20, 2013 at 01:42:04
@Echo off

set year=%1
if "%year%"=="" set /p year=Year?
if "%year%"=="" goto :eof
set /a mod=year %% 400
if %mod%==0 set leap=1 && goto :mkyear
set /a mod=year %% 100
if %mod%==0 set leap=0 && goto :mkyear
set /a mod=year %% 4
if %mod%==0 set leap=1 && goto :mkyear
set leap=0

:mkyear
call :mkmonth 01 01 31
call :mkmonth 02 02 28+leap
call :mkmonth 03 03 31
call :mkmonth 04 04 30
call :mkmonth 05 05 31
call :mkmonth 06 06 30
call :mkmonth 07 07 31
call :mkmonth 08 08 31
call :mkmonth 09 09 30
call :mkmonth 10 10 31
call :mkmonth 11 11 30
call :mkmonth 12 12 31
goto :eof

:mkmonth
set month=%1
set mname=%2
set /a ndays=%3
for /l %%d in (1,1,9) do echo > C:\WINDOWS\TEMP\"%year%%month%0%%d".log
for /l %%d in (10,1,%ndays%) do echo > C:\WINDOWS\TEMP\"%year%%month%%%d".log
CLS

Md C:\WINDOWS\TEMP\01
Md C:\WINDOWS\TEMP\02
Md C:\WINDOWS\TEMP\03
Md C:\WINDOWS\TEMP\04
Md C:\WINDOWS\TEMP\05
Md C:\WINDOWS\TEMP\06
Md C:\WINDOWS\TEMP\07
Md C:\WINDOWS\TEMP\08
Md C:\WINDOWS\TEMP\09
Md C:\WINDOWS\TEMP\10
Md C:\WINDOWS\TEMP\11
Md C:\WINDOWS\TEMP\12
CLS

Move c:\WINDOWS\TEMP\*201301*.log c:\WINDOWS\TEMP\01
Move c:\WINDOWS\TEMP\*201302*.log c:\WINDOWS\TEMP\02
Move c:\WINDOWS\TEMP\*201303*.log c:\WINDOWS\TEMP\03
Move c:\WINDOWS\TEMP\*201304*.log c:\WINDOWS\TEMP\04
Move c:\WINDOWS\TEMP\*201305*.log c:\WINDOWS\TEMP\05
Move c:\WINDOWS\TEMP\*201306*.log c:\WINDOWS\TEMP\06
Move c:\WINDOWS\TEMP\*201307*.log c:\WINDOWS\TEMP\07
Move c:\WINDOWS\TEMP\*201308*.log c:\WINDOWS\TEMP\08
Move c:\WINDOWS\TEMP\*201309*.log c:\WINDOWS\TEMP\09
Move c:\WINDOWS\TEMP\*201310*.log c:\WINDOWS\TEMP\10
Move c:\WINDOWS\TEMP\*201311*.log c:\WINDOWS\TEMP\11
Move c:\WINDOWS\TEMP\*201312*.log c:\WINDOWS\TEMP\12
CLS


Report •

#2
March 20, 2013 at 06:44:24
Are you looking to fabricate empty log files?

:: mike


Report •

#3
March 20, 2013 at 18:23:57
Like mike said... Oh well, here's version adapted from a very recent post:

@echo off & setlocal
set year=%1
set /a leap=28+3/(("year%%4"+1)*3)
set /a sub=335+leap
echo %sub%
set test=0
for /L %%a in (1 1 %sub%) do call :adddate
goto :eof

:adddate
set /a day+=1
if month=2 set test=%leap%
:: 4,6,9,11 30-day months
call :%month% 2>nul
if %day% gtr %test% call :eom
set da=0%day%
set ddate=%year%%mo%%da:~-2%
>c:\windows\temp\%mo%\%ddate% echo no_data
echo %ddate%
goto :eof

:eom
set day=1
set /a month+=1
echo month: %month%
set mo=0%month%
set mo=%mo:~-2%
md c:\windows\temp\%mo%
set test=31
goto :eof

:4
:6
:9
:11
set test=30
goto :eof

:12
:: this one's not needed for your application, but included anyway.
if %day% equ 32 (
set /a year+=1
echo HAPPY NEW YEAR
set month=0
)
set /a leap="28+3/((year%%4+1)*3)"
goto :eof
::==== end batchscript


Report •
Related Solutions


Ask Question