Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Make a folder named Date-Time

Jul
304
0
How can I set up an alias (?) so that I can use it in a batch file to create a folder with the current date and time?

Chuck
 
: -----Original Message-----
:
: How can I set up an alias (?) so that I can use it in a batch file to create a folder
with the current date
: and time?


Md "%@date[%_date %_time]
Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

Those will all work alias name MDT what ever you want to call it

Since the folder will be created with the same info why would you want to double up on it.
?
 
On Sun, 30 Oct 2011 17:15:30 -0400, Kachupp <> wrote:

|: -----Original Message-----
|:
|: How can I set up an alias (?) so that I can use it in a batch file to create a folder
|with the current date
|: and time?
|
|
|Md "%@date[%_date %_time]
|Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
|
|Those will all work alias name MDT what ever you want to call it

Also, if you don't mind the DATETIME format,

alias datedir `*md %_datetime`
 
When I ran

alias dd3 Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

or

alias dd2 Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"


it changed the alias to equal the folder name. So, the first time I ran it, it made

11-01-11 22.43.19

But then, dd3 turned into '11-01-11 22.43.19' so it couldn't create the folder as one with that name already existed.

Huh? Am I doing something wrong here?

Chuck
 
: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: When I ran
:
: alias dd3 Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: or
:
: alias dd2 Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
:
: it changed the alias to equal the folder name. So, the first time I ran it, it made
:
: 11-01-11 22.43.19
:
: But then, dd3 turned into '11-01-11 22.43.19' so it couldn't create the folder as one
with that name
: already existed.
:
: Huh? Am I doing something wrong here?
:
: Chuck

Timing. You will need a delay between issuing the aliases 2 seconds should be ample.
 
Of these two, the first still gave me errors (10 second pause), but the second one worked fine.

dd2=Md "%@date[%_date %_time]
dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

Thanks,
Charles
 
From: CWBillow
| Of these two, the first still gave me errors (10 second pause), but
| the second one worked fine.
|
| dd2=Md "%@date[%_date %_time]
| dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

From the format, I presume you do this in an alias definition file. Did you look at _isodate?
One more comment. The method of obtaining the date and time in separate calls to the OS has bit me in the past - if you happen to do it within a few milliseconds before midnight, the date and time returned could be from different days, resulting in a combination nearly 24 hours obsolete... Two methods available to fix this, one a lot more elaborate than would suit an alias: get date, get time, get date again - if dates mismatch, get time again. The other is to use the single call made obtaining _DATETIME, and editing its value into the format you want, along the lines (NOT TESTED!!!):

alias dd=`SET z=%_datetime %+ MD "%@instr[0,4,%z]-%@instr[4,2,%z]-%@instr[6,2,%z] %@instr[8,2,%z].%@instr[10,2,%z].%@instr[12,2,%z]"`

BTW, you can force _date and _time to return data in the format you want by setting the registry format for short date and time, either temporarily (for the execution of the MD command), or permanently.
--
HTH, Steve
 
Ooppps not surprised the first one gives an error ... the _time variable does not belong
there sorry! Chuck
Time is ignored! In dd2

: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: Of these two, the first still gave me errors (10 second pause), but the second one
worked fine.
:
: dd2=Md "%@date[%_date %_time]
: dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: Thanks,
: Charles
 
I don't know if any of your issues are related to not having backquotes
around your alias definition.

For example, these two definitions will yield different results:

alias mdd1=`Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"`
alias mdd2=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

alias
mdd1=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
mdd2=Md "11-02-11 10.53.51"

-Scott




Ooppps not surprised the first one gives an error ... the _time variable
does not belong
there sorry! Chuck
Time is ignored! In dd2

: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: Of these two, the first still gave me errors (10 second pause), but the
second one
worked fine.
:
: dd2=Md "%@date[%_date %_time]
: dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: Thanks,
: Charles
 
Cool! I'll give the [untested] alias a look.

Thanks,
Chuck

From: CWBillow
| Of these two, the first still gave me errors (10 second pause), but
| the second one worked fine.
|
| dd2=Md "%@date[%_date %_time]
| dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

From the format, I presume you do this in an alias definition file. Did you look at _isodate?
One more comment. The method of obtaining the date and time in separate calls to the OS has bit me in the past - if you happen to do it within a few milliseconds before midnight, the date and time returned could be from different days, resulting in a combination nearly 24 hours obsolete... Two methods available to fix this, one a lot more elaborate than would suit an alias: get date, get time, get date again - if dates mismatch, get time again. The other is to use the single call made obtaining _DATETIME, and editing its value into the format you want, along the lines (NOT TESTED!!!):

alias dd=`SET z=%_datetime %+ MD "%@instr[0,4,%z]-%@instr[4,2,%z]-%@instr[6,2,%z] %@instr[8,2,%z].%@instr[10,2,%z].%@instr[12,2,%z]"`

BTW, you can force _date and _time to return data in the format you want by setting the registry format for short date and time, either temporarily (for the execution of the MD command), or permanently.
--
HTH, Steve
 
Got it.

Thanks,
Chuck

Ooppps not surprised the first one gives an error ... the _time variable does not belong
there sorry! Chuck
Time is ignored! In dd2

: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: Of these two, the first still gave me errors (10 second pause), but the second one
worked fine.
:
: dd2=Md "%@date[%_date %_time]
: dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: Thanks,
: Charles
 
I'll try them, thanks.

Chuck



I don't know if any of your issues are related to not having backquotes
around your alias definition.

For example, these two definitions will yield different results:

alias mdd1=`Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"`
alias mdd2=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"

alias
mdd1=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
mdd2=Md "11-02-11 10.53.51"

-Scott




Ooppps not surprised the first one gives an error ... the _time variable
does not belong
there sorry! Chuck
Time is ignored! In dd2

: -----Original Message-----
: Subject: RE: [Support-t-3331] Re: Make a folder named Date-Time
:
: Of these two, the first still gave me errors (10 second pause), but the
second one
worked fine.
:
: dd2=Md "%@date[%_date %_time]
: dd3=Md "%@replace[/,-,%_date] %@replace[:,.,%_time]"
:
: Thanks,
: Charles
 
Guys, I just tried the various versions...now my only problem is which one I like the best!

You all were great. Thanks!

Chuck
 
I've been working on this, but don't have time right now to figure out what's wrong with mine... :(
Simply: I need to create a "YYYY-MM-DD HH-MM" foldername from an automated batch file, and Subst Z: for it.
The above looks almost right to me, but I'm getting folders named _date _time] and similar.
Any quick fixes? Thx...
 
Actually, use %_isodate instead of %_date and %_hour and %_minute for the time.

set foldername="%_isodate %_hour-%@right[2,0%_minute]"
subst /d Z: > nul
subst Z: %foldername
 
I only reference _date/_isodate, _hour, and _minute individually to obtain the current date and time if I can guarantee that midnight cannot occur between the first and last reference. Otherwise I always use a single access to the system clock, usually via _datetime, and if I need the individual elements I use @instr[] on the string returned:

set now=%_datetime
set foldername="%@instr[2,2,%now]-%@instr[2,2,%now]-%@instr[4,2,%now] %@instr[6,2,%now]-%@instr[8,2,%now]"

to generate a name in which the date (using 2-digit year) and time (using hyphen between hours and minutes, no seconds) are separated by a single space. For my own use, I typically use NO separators, which makes it much simpler; to avoid very large directories (e.g. the parent directory of all these folders) I typically break it into a hierarchy - for frequent items (e.g., pictures of events) I make year+month one level, and day+time a lower level. For less frequent items (e.g., monthly bills) year is the higher level.
--
HTH, Steve
 
I only reference _date/_isodate, _hour, and _minute individually to obtain the current date and time if I can guarantee that midnight cannot occur between the first and last reference. Otherwise I always use a single access to the system clock, usually via _datetime, and if I need the individual elements I use @instr[] on the string returned:

set now=%_datetime
set foldername="%@instr[2,2,%now]-%@instr[2,2,%now]-%@instr[4,2,%now] %@instr[6,2,%now]-%@instr[8,2,%now]"

to generate a name in which the date (using 2-digit year) and time (using hyphen between hours and minutes, no seconds) are separated by a single space. For my own use, I typically use NO separators, which makes it much simpler; to avoid very large directories (e.g. the parent directory of all these folders) I typically break it into a hierarchy - for frequent items (e.g., pictures of events) I make year+month one level, and day+time a lower level. For less frequent items (e.g., monthly bills) year is the higher level.
--
HTH, Steve
Hello Steve,

that's exactly the way I like (and do) it too.
 

Similar threads

Back
Top