iT邦幫忙

0

每天自動備份 bat檔名日期+不同字

XYZ 2019-09-05 11:07:301596 瀏覽

各位好,

下面的bat只能將C:\test\Backup\目錄下檔名固定是日期的自動備份
20190901.Zip
FOR /F "tokens=1-3 delims=/ " %%a IN ("%date%") DO (SET _today=%%a%%b%%c)
XCOPY "C:\test\Backup%_today%.zip" "E:\test Backup\DailyBackup" /K/E/Y/C/H

若每天C:\test\Backup\的目錄下都會產生今天的日期後面不同字的檔名,要怎麼自動備份至
E:\test Backup\DailyBackup\目錄下
如:
C:\test\Backup\20190901-123453.Zip
C:\test\Backup\20190902-123896.Zip
C:\test\Backup\20190903-12388596.Zip

所以一天只會有一個檔案?
XCOPY "C:\test\Backup%date:~0,4%%date:~5,2%%date:~8,2%*.zip" "E:\test Backup\DailyBackup" /K/E/Y/C/H

2 個回答

2
dragonH
iT邦超人 5 級 ‧ 2019-09-05 12:18:46
最佳解答

複製所有檔名包含當日的zip檔到指定位置

e.g.

20190905-123.zip
20190905-456.zip
20190905-123.copy.zip

@echo off
for /F "tokens=1-3 delims=/ " %%a IN ("%date%") DO SET _today=%%a%%b%%c
for %%f in (C:\test\Backup\%_today%-*.zip) do (
  XCOPY "%%f" "E:\test Backup\DailyBackup\" /K/E/Y/C/H/I
)
1
souda
iT邦研究生 2 級 ‧ 2019-09-05 13:14:34

set dd=%date:~8,2%
set dm=%date:~5,2%
set dy=%date:~0,4%
set mydate=%dy%%dm%%dd%
path "C:\Program Files\7-Zip"
7z
7z a -tzip "D:\xxx\xxx_bak_%mydate%.zip" "D:\xxx"

試看看瞜!

我要發表回答

立即登入回答