need batch file help

S

Simon Guertin

Hi, I need to create a folder with the current day's date
as the name

I don't want to type in any parameter.
the first bat file look like this:

call createDir.bat time /t

second bat file looks like this:
mkdir %1

What should I do to keep it simple?

thanks

Simon
 
P

Paul R. Sadowski

Simon Guertin said:
Hi, I need to create a folder with the current day's date
as the name

I don't want to type in any parameter.
the first bat file look like this:

call createDir.bat time /t

time displays the time not the date. DATE /t would show the date.

I do it this way in a batch file:

setlocal ENABLEEXTENSIONS
for /f "tokens=1-2" %%c in ("%DATE%") do set TheDate=%%d
for /f "delims=/; tokens=1-3" %%c in ("%TheDate%") do set TheDate=%%c%%d%%e
mkdir X:\%TheDate%.

Which would create the dir
X:\04152004

%%c is the month
%%d is the day
%%e is the year

You can rearrange them for the best format for you in the set command.
for /f "delims=/; tokens=1-3" %%c in ("%TheDate%") do set TheDate=%%c%%d%%e
04152004
for /f "delims=/; tokens=1-3" %%c in ("%TheDate%") do set TheDate=%%e%%c%%d
20040415 (my prefered format)
for /f "delims=/; tokens=1-3" %%c in ("%TheDate%") do set TheDate=%%d%%c%%e
15042004

Should be fairly simnple to localize for your settings.
 
W

wadester

Hi, I need to create a folder with the current day's date
as the name

I don't want to type in any parameter.
the first bat file look like this:

call createDir.bat time /t

second bat file looks like this:
mkdir %1

What should I do to keep it simple?

thanks

Simon

Here it is in one line. You didn;t specify the format of the name, so
this just makes a directory named MMDDYYYY:

for /f "tokens=2,3,4 delims=/ " %i in ('date /t') do md %i%j%k

Double the % in a batch file.

ws
 
G

guard

Hi, I need to create a folder with the current day's date
as the name

I don't want to type in any parameter.
the first bat file look like this:

call createDir.bat time /t

second bat file looks like this:
mkdir %1

What should I do to keep it simple?

GetLogDate will give you YYYYMMDD in the variable #LogDate.

%.GetLogDate%
MKDIR %#LogDate%

See (http://TheSystemGuard.com/MtCmds/GetValue/GetLogDate.htm)

GetLogDate is part of the FREE Advanced Command Library.
(http://ntlib.com)

*******

-tsg

/-----------------+---------------+----------------------\
| COMPATIBILITY | CLARITY | SPEED |
| Write code ONCE | Make it clear | THEN...Make it fast! |
\-----------------+---------------+----------------------/
400+ command-line resources using ONLY native NT commands!
(http://TheSystemGuard.com/default.asp#MasterCommandList)
 

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