Win10 regularly deletes log files that are N days old under the specified path

Windows regularly deletes log files that are N days old under the specified path

Windows regularly deletes log files that are N days old under the specified path

The content of the bat script file under Windows is

1. Delete all files older than 5 days under the specified path

@echo off
set SrcDir=E:\WORK\Git
set DaysAgo=5
forfiles /p %SrcDir% /s /m *.*/d -%DaysAgo% /c "cmd /c del /f /q /a @path"

2. Delete all log files under the specified path 5 days ago

@echo off
set SrcDir=E:\WORK\Git //指定的路径
set DaysAgo=5 //5天前
forfiles /p %SrcDir% /s /m *.log/d -%DaysAgo% /c "cmd /c del /f /q /a @path"

*.log is the filtered file format. Similarly, if you delete jpg image format files, you can replace them with .jpg here.

3. Windows runs bat file regularly

1. In the WIN10 system, select Computer Management -> System Tools -> Task Scheduler, create a task
Insert image description here
2. In the pop-up "Create Task" box, set it in General
Insert image description here
3. In Trigger -> New, and set a scheduled run time point and frequency

Insert image description here
4. Operation->New->Open the written bat script file, and click OK to save.
Insert image description here
Then return to the computer management interface. You can find the "Scheduled automatic deletion" in System Tools->Task Scheduler->Task Scheduler. Mission accomplished.

Guess you like

Origin blog.csdn.net/weixin_43741718/article/details/130992254