cmd:在檔案名稱中包含日期和時間

cmd:在檔案名稱中包含日期和時間

如何取得檔案名稱 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

相關內容