cmd line rename file with date and time

后端 未结 7 1547
余生分开走
余生分开走 2020-12-14 11:03

Project moving forwards, I can see why creating .bat files to do things can become addictive! I can now save somefile.txt at regular intervals, I then rename somefile.txt by

7条回答
  •  借酒劲吻你
    2020-12-14 11:32

    Digging up the old thread because all solutions have missed the simplest fix...

    It is failing because the substitution of the time variable results in a space in the filename, meaning it treats the last part of the filename as a parameter into the command.

    The simplest solution is to just surround the desired filename in quotes "filename".

    Then you can have any date pattern you want (with the exception of those illegal characters such as /,\,...)

    I would suggest reverse date order YYYYMMDD-HHMM:

    ren "somefile.txt" "somefile-%date:~10,4%%date:~7,2%%date:~4,2%-%time:~0,2%%time:~3,2%.txt"
    

提交回复
热议问题