creating folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
joe
Posts: 35
Joined: 06 Sep 2017 07:56

creating folder

#1 Post by joe » 16 Dec 2017 06:40

hi,

can someone please help me.

create a folder based on the current month & year (ie... December 2017, January 2018 and so on)

it should change automatically every month..

thanx in advance

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: creating folder

#2 Post by Squashman » 16 Dec 2017 08:30

This was all from searching the forums and the Internet. The list goes on and on.

Code: Select all

@echo off
REM Get date and time in YYYYMMDDhhmmss format
for /f "tokens=2 delims==." %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "months=01-January;02-February;03-March;04-April;05-May;06-June;07-July;08-August;09-September;10-October;11-November;12-December"
CALL set "months=%%months:*%MM%-=%%"
(set "monthname=%months:;=" & set /p "=%" ) <nul >nul

echo %monthname% %YYYY%

pause
or

Code: Select all

@echo off
setlocal EnableDelayedExpansion
for /f "tokens=2 delims==." %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"

set m=100
for %%m in (January February March April May June July August September October November  December) do (
   set /A m+=1
   set "month[!m:~-2!]=%%m"
)
set "monthName=!month[%MM%]!"
echo %monthName% %YYYY%
pause
or

Code: Select all

@echo off
for /f "tokens=2 delims==." %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
IF "%MM:~0,1%"=="0" SET "MM=%MM:~1%"
FOR /f "tokens=%MM%" %%G in ("January February March April May June July August September October November  December") do set monthname=%%G
echo %monthName% %YYYY%
pause

joe
Posts: 35
Joined: 06 Sep 2017 07:56

Re: creating folder

#3 Post by joe » 16 Dec 2017 08:56

hi

thank you squashman so kind of you..
have a nice weekend..

Post Reply