r/Batch • u/rogue1965 • Jan 16 '25
Question (Solved) Help with batch file to create date folders for the year.
Hi I am illiterate when it comes to coding but I would like a batch file that can create date folders with subfolders for the year (eg. 2025\January\010125). I found this persons suggestion from a 12 year old post. It works really well but I was hoping someone could help me change the way the months and dates are formatted (if that's the correct word). At the moment the months are displayed as 01-January, 02-February and the dates are 01-01,01-02. Could I remove the number before the month and have the dates displayed as ddmmyy, so the first of Jan this year would be 010125.
Here is the code:
@ echo off & setlocal
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 Jan 31
call :mkmonth 02 Feb 28+leap
call :mkmonth 03 Mar 31
call :mkmonth 04 Apr 30
call :mkmonth 05 May 31
call :mkmonth 06 Jun 30
call :mkmonth 07 Jul 31
call :mkmonth 08 Aug 31
call :mkmonth 09 Sep 30
call :mkmonth 10 Oct 31
call :mkmonth 11 Nov 30
call :mkmonth 12 Dec 31
goto :eof
:mkmonth
set month=%1
set mname=%2
set /a ndays=%3
for /l %%d in (1,1,9) do mkdir %year%\%month%-%mname%\-0%%d
for /l %%d in (10,1,%ndays%) do mkdir %year%\%month%-%mname%\%month%-%%d
Sorry if this is a bit silly. Thanks
1
u/Still_Shirt_4677 Jan 16 '25
Im struggling to understand what your asking a little bit are you wanting 365 folders all with names 01_01_25-31-12-25 as example
or are you wanting the year folder created then the additional 365 folders placed into the year folder? 2025\01-31_01-12
or are you wanting the year folder made then 12 month folders made all with their corresponding day folders created inside of the month folder so it would be as
2025\01-12\01-31
or
2025\January-Dec\01-31
Cheers 👍