window powershell 定時刪除文件腳本

@echo off
REM ------------------------------------------------------------------------------
REM Created by Shine Li at 2017-10-30
REM 功能:定期刪除數據庫備份文件
REM 設置DayAgo參數來保留最近多少天的備份
REM ------------------------------------------------------------------------------
REM ------------------------------------------------------------------------------
REM 如果顯示的待刪除文件列表正確無誤
REM 把 Select-Object FullName 修改成 Remove-Item -Force 再次執行即可真正刪除文件
REM Win7/Win8/Win10等系統自帶PowerShell
REM ------------------------------------------------------------------------------
set Dir=G:\schedule_jobs
REM 指定待刪除文件的存放路徑
set SrcDir=G:\app\Administrator\admin\dz\dpdump
REM 指定天數
set DaysAgo=30


echo =================================begin to delete backup===============================>>%Dir%\del_backup.log
powershell -c "Get-ChildItem -Path '%SrcDir%' -Recurse -ErrorAction:SilentlyContinue | Where-Object -FilterScript {(((get-date) - ($_.LastWriteTime)).days -gt %DaysAgo% -and $_.PsISContainer -ne $True)} | Select-Object FullName">>%Dir%\del_backup.log


powershell -c "Get-ChildItem -Path '%SrcDir%' -Recurse -ErrorAction:SilentlyContinue | Where-Object -FilterScript {(((get-date) - ($_.LastWriteTime)).days -gt %DaysAgo% -and $_.PsISContainer -ne $True)} | Remove-Item -Force"


echo =====================================delete completed......===========================>>%Dir%\del_backup.log
rem pause
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章