Make a folder named Date-Time

Aug 9, 2009
228
1
: -----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.
?
 
May 20, 2008
11,379
98
Syracuse, NY, USA
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`
 
Jul 12, 2008
286
0
Las Vegas, NV
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
 
Aug 9, 2009
228
1
: -----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.
 
Jul 12, 2008
286
0
Las Vegas, NV
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
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
 
Aug 9, 2009
228
1
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
 

samintz

Scott Mintz
May 20, 2008
1,495
16
Solon, OH, USA
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
 
Jul 12, 2008
286
0
Las Vegas, NV
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
 
Jul 12, 2008
286
0
Las Vegas, NV
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
 
Jul 12, 2008
286
0
Las Vegas, NV
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
 
Sep 19, 2011
1
0
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...
 

samintz

Scott Mintz
May 20, 2008
1,495
16
Solon, OH, USA
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
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
 
Aug 2, 2011
258
4
Berlin, Germany
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
Thread starter Title Forum Replies Date
fishman@panix.com Startup Folder? Support 3
C writing folder names with JPSoft special chars like &...... Support 4
R How to? Set default application in a special folder Support 4
R How to? Open Take Command at current folder Support 7
D How to? Pass OpenHere Folder to CMD? Support 6
Chen Touboul When i try to delete an empty folder i got "the dirctoy name is invalid" Support 3
C How to bypass UAC warning when shortcut in \Startup folder ? Support 9
CWBillow Clearing out the Windows Temp folder Support 2
J directory or folder to start in Support 2
vefatica Refresh a folder in File Explorer? Support 0
P How to? Delete subfolders but not the folder itself Support 11
vefatica Shortcut/start-up folder nonsense Support 20
cgunhouse Crash on View/Folder Support 1
D Fixed Cut and paste in TC's file/folder view does not remove file Support 17
D Version 18 changed the naming convention of TC's folder Support 5
C How to? COPY ftp folder query Support 7
fpefpe How to? folder / explorer window Support 10
rps Documentation Folder combo box docs Support 1
J Startup folder Support 6
C DEL, connected Web folder, report Support 1
T How to? Adding TCC to startup folder Support 6
jbanaszczyk TCMD 16 Install - download folder Support 2
I How to? Save and restore folder timestamps Support 22
gschizas How to? How can I use select with a folder that already contains parentheses? Support 7
C Suggestions for Compare Folder Tree routine Support 5
J Change folder TCC starts in Support 2
gschizas Installation folder for TCMD x64 15.1 is wrong Support 5
D Folder/List view changed in v15 Support 8
C Startup folder not working on v15 Support 6
N WAD Take Command and UNCs for Folder List Support 10
M Sync folder/list view with command window? Support 2
aedthuio Folder with space char Support 6
fpefpe How to? Plugin Folder Support 1
vefatica New desktop and StartUp folder? Support 4
M Folder View Freezing Support 10
C Problem navigating folder view Support 11
vefatica OT:Explain Win7's "start menu" folder? Support 17
CWBillow Sync Folder Tree and Command Window? Support 11
L Thanks from larryalk was Cannot apply Start in folder for Tcmd Support 11
L Cannot apply Start In folder for Tcmd Support 15
J Find Files - changing folder Support 1
JohnQSmith Folder pane right-click rename Support 2
Phileosophos Unzip doesn't extract to specified output folder Support 5
D Changed order of folder names in @file Support 4
C how to copy to folder where I need admin rights Support 5
P Sync /w won't delete in ftp folder Support 1
S Can Take Command show TortoiseSvn folder icons? Support 9
gschizas pdir crashes horribly in one specific folder Support 5
D Always get shortcut in Start Menu folder Support 6
D How to set folder directory from command line? Support 4

Similar threads