1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Make a folder named Date-Time

Discussion in 'Support' started by CWBillow, Oct 30, 2011.

  1. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    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
     
  2. Kachupp

    Joined:
    Aug 9, 2009
    Messages:
    133
    Likes Received:
    0
    : -----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.
    ?
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,959
    Likes Received:
    30
    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`
     
  4. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    Cool. Thanks guys.

    Chuck
     
  5. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    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
     
  6. Kachupp

    Joined:
    Aug 9, 2009
    Messages:
    133
    Likes Received:
    0
    : -----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.
     
  7. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    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
     
  8. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  9. Kachupp

    Joined:
    Aug 9, 2009
    Messages:
    133
    Likes Received:
    0
    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
     
  10. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    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
     
  11. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    Cool! I'll give the [untested] alias a look.

    Thanks,
    Chuck

     
  12. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    Got it.

    Thanks,
    Chuck

     
  13. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    I'll try them, thanks.

    Chuck



     
  14. CWBillow

    Joined:
    Jul 12, 2008
    Messages:
    194
    Likes Received:
    0
    Guys, I just tried the various versions...now my only problem is which one I like the best!

    You all were great. Thanks!

    Chuck
     
  15. PartyRambo

    Joined:
    Sep 19, 2011
    Messages:
    1
    Likes Received:
    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...
     
  16. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    set foldername="%_date %_time"
    subst /d Z: > nul
    subst Z: %foldername
     
  17. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    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
     
  18. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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
     
  19. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    Hello Steve,

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

Share This Page