我如何才能获得文件名 YYYY.MM.DD_HH.MM.SS.7z?它应该适用于任何区域设置!
问题不是重复7-Zip CMD:将当前日期添加到存档中,并仅包含存档中最后修改的文件夹因为我也需要几秒钟。
问候,
答案1
虽然从技术上讲这个问题是不同的问题,但答案本质上与另一个问题相同:
Echo "%DATE:~-4%.%DATE:~4,2%.%DATE:~7,2%_%TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%
但是,由于您指定它必须适用于任何区域设置,因此该答案不能完全满足您的需求。据我所知,在 cmd.exe 中没有办法原生地满足您的需求。我强烈建议在 powershell 而不是 cmd 中执行此操作。
答案2
命令:
echo "%DATE:~10,4%.%DATE:~7,2%.%DATE:~4,2%_%TIME:~0,2%.%TIME:~3,2%.%TIME:~6,2%.7z"
输出:
"2012.27.05_22.11.58.7z"
答案3
@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