Batch file 具有创建日期的zip文件

Batch file 具有创建日期的zip文件,batch-file,zip,Batch File,Zip,你能建议我如何压缩它的子文件夹下的文件夹下的文件,并用批处理脚本的创建日期重命名该文件,然后删除原始文件。它应该能够配置归档的天数。例如,如果我想归档任何超过7天的文件,它应该压缩超过7天的文件。并且还可以配置删除文件 例如,文件是2016年9月14日创建的abc.log,它将被压缩并重命名为abc.20160914.zip 我在论坛中搜索,但没有找到。非常感谢你的帮助。我找到了答案 @echo off setlocal enabledelayedexpansion set Archiv

你能建议我如何压缩它的子文件夹下的文件夹下的文件,并用批处理脚本的创建日期重命名该文件,然后删除原始文件。它应该能够配置归档的天数。例如,如果我想归档任何超过7天的文件,它应该压缩超过7天的文件。并且还可以配置删除文件

例如,文件是2016年9月14日创建的abc.log,它将被压缩并重命名为abc.20160914.zip


我在论坛中搜索,但没有找到。非常感谢你的帮助。

我找到了答案

    @echo off
setlocal enabledelayedexpansion
set Archive=D:\scripts\test\Archive
set Temp=D:\scripts\test\Temp
set DaytoDelete=7

REM Moving file older than %DaytoDelete% days to TEMP folder
for /f "tokens=*" %%G in (D:\scripts\test\Location.txt) do  (
forfiles -p "%%G" -s -m *.log -d -%DaytoDelete% -c "cmd /c move @path %TEMP%"
)
if not exist "%Archive%" (md "%Archive%")
if not exist "%Temp%" (md "%Temp%")

REM Zip file in %Temp% and rename zip file with creation date
for %%a in ("%Temp%\*.log") do (
    echo Processing %%~nxa ...
    set File=%%~fa
    set Archive=D:\scripts\test\Archive

    for /f "tokens=1* delims=," %%a in ('wmic datafile where "name='!File:\=\\!'" get 'CreationDate' /format:csv ^| find /i "%ComputerName%"') do (set CreationDate=%%b)
    echo %%~nxa: !CreationDate!
    set cYear=!CreationDate:~0,4!
    set cMonth=!CreationDate:~4,2!
    set cDay=!CreationDate:~6,2!
    set FileTime=!cYear!!cMonth!!cDay!

    REM zip "%Archive%\temp.zip" %%~fa Issue with zip command, it zips whole full path of file
    "C:\Program Files\7-Zip\7z.exe" a -tzip "%Archive%\temp.zip" %%~fa
    ren %Archive%\temp.zip %%~na.!FileTime!.zip
)

REM Delete file after zipping
DEL /F /S /Q %Temp%\*.*
pause

你好,迪ệ请您发布一些您尝试过或看过的批处理代码。您使用的是Winrar、7zip等吗