Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
foncesa
- Posts: 42
- Joined: 12 Sep 2013 00:09
#1
Post
by foncesa » 03 Oct 2013 12:58
Hi,
This script creates the folder as todays date.
Code: Select all
for /F "tokens=1-4 delims=. " %%i in ('date /t') do (
set Day=%%i
set Month=%%j
set Year=%%k
)
md %-%%Year%%Month%%Day%
Is there a way that on 1st day of every month a batch script is used to create the full month date folder in a single go. I mean to say if on 1st october i run a batch file which will create 31 folders as date. So that i don't need to run this every day.
Any ways to do this?
-
aGerman
- Expert
- Posts: 4743
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 03 Oct 2013 13:58
Seems your date format is dd.mm.yyyy
Try
Code: Select all
@echo off &setlocal
for /f "tokens=2,3 delims=." %%i in ("%date:* =%") do (
set /a "m = 100%%i %% 100, yy = %%j"
set "mm=%%i"
)
set /a "n=30 + !(((m & 9) + 6) %% 7) + !(m ^ 2) * (!(yy %% 4) - !(yy %% 100) + !(yy %% 400) - 2)"
setlocal EnableDelayedExpansion
for /l %%i in (1 1 %n%) do (
set "dd=0%%i"
2>nul md %yy%%mm%!dd:~-2!
)
Regards
aGerman
-
foncesa
- Posts: 42
- Joined: 12 Sep 2013 00:09
#3
Post
by foncesa » 05 Oct 2013 05:26
Thanks for response, It creates the folders in sequence from 1 to 30 but does not create with dd.mm.yyyy.
-
aGerman
- Expert
- Posts: 4743
- Joined: 22 Jan 2010 18:01
- Location: Germany
#4
Post
by aGerman » 05 Oct 2013 05:38
When I talked about format dd.mm.yyyy I meant the order that
echo %date%
would display for you. Or wouldn't it?
Now I'm unsure. Is that the manner your folders should look like? The code in your initial post would create folders in style yyyymmdd. My code should do the same (I hope).
Regards
aGerman