Announcement

Collapse
No announcement yet.

Rename to timestamp

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rename to timestamp

    I will be creating a batch that
    1 copies a results file to a remote fileshare
    and then renames the file to

    obviously the copy is easy--
    the rename to is harder

    I would like to include a line in the batch

    example--

    copy *.txt \\server\share
    ren *.txt *.033109_927am

    This works for date-- but I need time as well

    ren *.txt *.%date:~7,2%%date:~4,2%

    Any help?

  • #2
    Re: Rename to timestamp

    Got it
    -- just thought I'd share it


    copy *.txt \\server\share

    PING -n 5 127.0.0.1>nul

    set hh=%time:~0,2%

    REM Since there is no leading zero for times before 10 am, have to put in

    REM a zero when this is run before 10 am.

    if "%time:~0,1%"==" " set hh=0%hh:~1,1%

    set yyyymmdd-hhmmss=%date:~-4,4%%date:~-10,2%%date:~-7,2%-%hh%%time:~-8,2%%time:~-5,2%

    REM ren *.txt DATA-%yyyymmdd-hhmmss%
    or
    ren *.txt *.DATA-%yyyymmdd-hhmmss%

    Comment


    • #3
      Re: Rename to timestamp

      Thanks for sharing.
      Andrew

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      Comment

      Working...
      X