PC Review


Reply
Thread Tools Rate Thread

Create a Dir with date

 
 
Jim
Guest
Posts: n/a
 
      13th Nov 2007
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.


 
Reply With Quote
 
 
 
 
Tom Lavedas
Guest
Posts: n/a
 
      13th Nov 2007
On Nov 13, 12:37 pm, "Jim" <stops...@redmond.com> wrote:
> 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.


This is the FAQ of FAQs for batch oriented programming. A google
search should easily find a myriad of examples along the lines of ...

:: Batch to creare a DATE named folder at the current location
echo off
for /f "tokens=2-4 delims=/ " %%a in ('echo %date%') do mkdir %%c-%%a
%-%%b

I adjusted the US date format to make it the sortable yyyy-mm-dd
layout. Other locales would probably need to be %%c-%%b-%%a to yield
the same yyyy-mm-dd.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

 
Reply With Quote
 
Matt Williamson
Guest
Posts: n/a
 
      14th Nov 2007
> 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


This is heavily dependent on your regional settings. What do you get when
you echo %date%? There are many ways to do it, but the most appropriate way
is to code for any possible date format. This requires a lot more code
though and is only necessary if you need to do it on many systems with
different regional formats. I generally do it this way using a short date
format of mm/dd/yyyy.

set dt=%date:/=-%&md %dt%

which just takes the input of %date% which is "11/14/2007" and replaces any
"/" with "-" to make it compatible with the characters windows accepts to
create a folder.

HTH

Matt



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Dean Wells \(MVP\)
Guest
Posts: n/a
 
      18th Nov 2007
That won't function; delayed expansion is sadly not a default behavior.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


"Matt Williamson" <(E-Mail Removed)> wrote in message
news:473b4f73$0$26481$(E-Mail Removed)...
>> 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

>
> This is heavily dependent on your regional settings. What do you get
> when you echo %date%? There are many ways to do it, but the most
> appropriate way is to code for any possible date format. This requires
> a lot more code though and is only necessary if you need to do it on
> many systems with different regional formats. I generally do it this
> way using a short date format of mm/dd/yyyy.
>
> set dt=%date:/=-%&md %dt%
>
> which just takes the input of %date% which is "11/14/2007" and
> replaces any "/" with "-" to make it compatible with the characters
> windows accepts to create a folder.
>
> HTH
>
> Matt
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



 
Reply With Quote
 
Tom Lavedas
Guest
Posts: n/a
 
      19th Nov 2007
On Nov 17, 9:06 pm, "Dean Wells \(MVP\)"
<dwe...@maskmsetechnology.com> wrote:
> That won't function; delayed expansion is sadly not a default behavior.
>
> --
> Dean Wells [MVP / Directory Services]
> MSEtechnology
> [[ Please respond to the Newsgroup only regarding posts ]]
> R e m o v e t h e m a s k t o s e n d e m a i l
>
> "Matt Williamson" <ih8s...@spamsux.org> wrote in message
>
> news:473b4f73$0$26481$(E-Mail Removed)...
>
> >> 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

>
> > This is heavily dependent on your regional settings. What do you get
> > when you echo %date%? There are many ways to do it, but the most
> > appropriate way is to code for any possible date format. This requires
> > a lot more code though and is only necessary if you need to do it on
> > many systems with different regional formats. I generally do it this
> > way using a short date format of mm/dd/yyyy.

>
> > set dt=%date:/=-%&md %dt%

>
> > which just takes the input of %date% which is "11/14/2007" and
> > replaces any "/" with "-" to make it compatible with the characters
> > windows accepts to create a folder.

>
> > HTH

>
> > Matt

>
> > --
> > Posted via a free Usenet account fromhttp://www.teranews.com


Nor does it remove the day-name that %DATE% returns, even if it is
done as successive statements. Though it is a better way to remove
the problematic hyphens for the stated reason of locale independance.

Working with Mr. Williamson's approach I was able to find this
adaptation that does NOT need delayed expansion ...

for /f "tokens=2" %a in ("%date:/=-%") do md %a

It solves both problems and remains one (rather complicated) statement
at the command line - or a single statement in a batch procedure when
the percent signs are doubled.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create vertical line to indicate date on chart with series of date ryguy7272 Microsoft Excel Charting 1 11th Jan 2008 06:36 PM
Create Formula - Add # of Networkdays to a specific start date to find an end date bdicarlo1@yahoo.com Microsoft Excel Discussion 3 9th Jan 2007 12:40 PM
Create Formula - Add # of Networkdays to a specific start date to find an end date bdicarlo1@yahoo.com Microsoft Excel Discussion 0 8th Jan 2007 11:32 PM
Create a button that will date stamp todays date in a cell Tom Meacham Microsoft Excel Misc 3 11th Jan 2006 01:08 AM
create a task request with due date...how can i create a calendar? kevin Microsoft Outlook VBA Programming 1 3rd May 2004 11:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:44 AM.