Making a directory with a date?

J

Jim

Using Windows XP or Win 2003 Server.
Is there a way to make a batch file that will create a new folder with the
date?

For example, if it were this easy....,
MKDIR %DATE% would make a directory 11-13-2007

Thanks.
 
P

Pegasus \(MVP\)

Unfortunately the author of this page got things somewhat confused.
He wrote that the command should look like so in a batch file:

echo md %%date:~-4,4%%\%%date:~-10,2%%\%%date:~-7,2%%

whereas in "DOS" it should look like so:

echo md %date:~-4,4%\%date:~-10,2%\%date:~-7,2%

There are two problems here:
a) There is no DOS under Windows, only the Command Prompt.
b) The first command is wrong. The second command is correct,
both in a batch file and in a Command Prompt.

You could also use this syntax, giving you a somewhat different result:

echo md "%date:/=%"
 
D

David Webb

I use the following script within CMD files in Win2K, WinXP, and Vista to create
folders named in the mmddyyyy format:

for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set mdate=%%A%%B%%C
md %mdate%

I am not the author of this script...all I know is that it works.
 
P

Pegasus \(MVP\)

You must place both lines into a batch file, then run the
batch file. If you still have a proble, post your version
of the batch file here and quote all error messages.
"It does not seem to run" does not tell us a great deal.
 
D

David Webb

Yes, that's all there is to it.

To create the command file, create a new text file on your top level folder,
open it and
copy the script contents then paste them into the body of this new file and then
save (using save-as) the file as "CreateDateFolder.cmd", with the quotes. You
should then have a New
Document.txt and a CreateDateFolder.cmd in your folder. You can delete the TXT
file.

If you prefer a batch file, use the BAT file extension instead of CMD.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top