@echo off
Set CurrentDate=%date:6,4%-%date:3,2%-%date:~0,2%
Set CurrentTime=%time:0,2%-%time:3,2%-%time:~6,2%
Set CurrentDateTime=%CurrentDate%
for /f "tokens=1-4 delims=/ " %%a in (‘date /t’) do (
set month=%%a
set day=%%b
set year=%%c
)
:: 确保月和日始终为两位数
if 1%month% LSS 20 (set month=0%month%)
if 1%day% LSS 20 (set day=0%day%)
:: 创建文件夹
set today=%month%%day%%year%
mkdir “D:\auditLogBak\bak%today%”
xcopy /e /i /c /y “C:\Windows\System32\winevt\Logs” “D:\auditLogBak\bak%today%”
@echo off
setlocal
:: 设置目标目录
set “TARGET_DIR=D:\auditLogBak\bak”
:: 进入目标目录
cd /d “%TARGET_DIR%”
:: 删除181天前的文件
forfiles /p “%TARGET_DIR%” /d -181 /c “cmd /c rd /s /q @path”
forfiles /p “%TARGET_DIR%” /d -181 /c “cmd /c del /f /q /a @path”
endlocal
echo Done.