Regarding Batch File (.bat or .cmd file programming) RRS feed

  • Question

  • Hi,

    I am trying to rename a file as

    "Serial number_File name_Current Date and Time"

    Which assigns the prefix as serial number, then the file name and the suffix as current date and time.

    This should be done for all file.

    The code that I am trying is :


    @ echo off

    echo Your File has been moved to the destination folder.

    ren C:\Users\kunjay_shah\kunjay\src\*.* *.*_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.txt

    : SET count=1
    : FOR %%F IN (C:\Users\kunjay_shah\kunjay\src\*.*) "%%~dpF!count!.txt" & SET /a count=!count!+1

    move C:\Users\kunjay_shah\kunjay\src\*.* C:\Users\kunjay_shah\kunjay\dst\

    :rename C:\Users\kunjay_shah\kunjay\dst\*.* *.*_%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%.txt
    :set HR=%time:~0,2%
     :   set HR=%Hr: =0% 
      :  set HR=%HR: =%

    : for /f "tokens=1-5 delims=/ " %%d in ("%date%" "%time%") do rename "C:\Users\kunjay_shah\kunjay\dst\*.*" %%e-%%f-%%g - %%d-%%e.txt

    : for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "C:\Users\kunjay_shah\kunjay\dst\*.*" %%e-%%f-%%g.txt

    : for /f "tokens=1-5 delims=:" %%d in ("%time%") do rename "C:\Users\kunjay_shah\kunjay\dst\*.*" %%d-%%e.txt

    : pause

    Please advise.

    Regards, Kunjay Shah

    • Moved by litdev Tuesday, July 22, 2014 6:39 PM
    Tuesday, July 22, 2014 2:40 PM


All replies

  • Sorry, but this is the Microsoft Small Basic programming language forum. Please ask this on a forum regarding batch scripts.

    Please mark any answers and "vote as helpful" any posts that help you!

    Tuesday, July 22, 2014 6:32 PM
  • Hello,

    I'd ask in The Official Scripting Guys Forum!


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

    Tuesday, July 22, 2014 9:19 PM