Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5073
  • Last Modified:

Create a folder using current date as the name...

This question has probably been ask a thousand times but here goes one more time...

 I would to use a bat file to create a folder that uses the current date as the name of the folder, IE. something like or close to "5-2-2005". I tried using md "%date%", but I get a folder called "Mon 05" containing a subfolder called "02" and containing yet another subfolder called "2005". I know very little about DOS scripting so I have searched high and low & have come up with nothing. So, once again I will ask for your help.

 Thanks,
RBennett
0
Ryan Bennett
Asked:
Ryan Bennett
  • 2
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Here's a script that should give you the flexibility to do this as you want it to appear:


Set MM=%date:~4,2%
Set DD=%date:~7,2%
Set YYYY=%date:~-4%
MD %MM%-%DD%-%YYYY%

Of course, you could also use:
MD %date:~4,2%-%date:~7,2%-%date:~-4%

0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
To explain a little further:

REM set the variable MM to the value of the %date% variable, but only take
REM the two characters starting at the 4th character (and remember the first
REM character is character 0)
Set MM=%date:~4,2%

REM Like above, only take the 2 characters starting at the 7th character
Set DD=%date:~7,2%

REM Like above, only take the last 4 (-4) characters from %date%
Set YYYY=%date:~-4%
MD %MM%-%DD%-%YYYY%
0
 
Ryan BennettAuthor Commented:
I guess it helps if you know what you're doing. Exactly what I've been trying to do.

 Thanks a bunch,
RBennett
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now