1

How can I get a filename YYYY.MM.DD_HH.MM.SS.7z? It should work with any regional settings!

The question is not duplicating 7-Zip CMD: Add current date to archive and include only the last modified folder in archive since I need seconds as well.

Regards,

noober
  • 233

3 Answers3

3

Well while this question is technically a different question, the answer is essentially the same as that other question:

Echo "%DATE:~-4%.%DATE:~4,2%.%DATE:~7,2%_%TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%

Since you specified that it must work with any regional settings though, that answer does not completely meet your needs. As far as I know, there is no way to meet your needs natively within cmd.exe. I would highly recommend doing this in powershell instead of cmd.

EBGreen
  • 9,655
0
@echo off
color 4f
mode 40,3
title Rename to date and time
::
:: Chunks gathered 'here & there'...
:: Batch rename 1 by 1 w. short delay, 
:: to date + time w. milliseconds => 
:: no overwriting.
::
:: Western European regional settings:
:: OK. ANY regional settings: ?.. Might 
:: require 'env. variables' replacement.
::

:7ZLOOP
setlocal
set "source=1_7z-orig-files-dir"
set "target=2_tmp"
::
if not exist "%target%\" md "%target%"
if not exist "%source%\*.7z" goto END
for %%F in ("%source%\*.7z") do (
set "file=%%~nxF"
move /y "%%F" "%target%" >nul
goto :break
)
:break
::   %time:~-2,2%  and  :loop set 
::   to 250  prevent overwriting:
::
set d=%date:~-4,4%-%date:~-7,2%-%date:~-10,2%
set d=%d: =_%
set t=%time:~-11,2%-%time:~-8,2%-%time:~-5,2%__%time:~-2,2%
set t=%t: =0%
::
ren "2_tmp\*.*" "%d%__%t%.*"
:loop
set /a count = count + 1
if %count%==250 goto endloop
goto loop
:endloop 
::
move /y 2_tmp\*.* .\
endlocal
goto 7ZLOOP
:END
Robert
  • 8,055
0

Command:

echo "%DATE:~10,4%.%DATE:~7,2%.%DATE:~4,2%_%TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%.7z"

Output:

"2012.27.05_22.11.58.7z"
Siva Charan
  • 4,959