Windows automatically deletes files for 7 days

Source: Internet
Author: User

Server is Windows Server 2012

Put it in the head office room to pick up the data.

But the disk that saves the data is not cleaned up for a while and will be full.

and can only manually clean up a directory at a time, because there are too many files, a clean-up, the disk is stuck.

This is the directory structure. Scan_bak is the total directory, the following is the date directory. There are many txt files inside.

E:\server\Remote\scan_bak

->20150921

->cn_343u098097fiyf544fdlf.txt

The main is to delete the date folder, keep the last 7 days of the directory.


Every manual cleanup is too much trouble. So I wrote a bat file.

The contents are as follows:


echo "#############################" >> E:\cmd\clean_scan_bak_log.txt

echo Start time:%date%_%time% >> E:\cmd\clean_scan_bak_log.txt


forfiles/p "E:\server\Remote\scan_bak"/s/m * */d-7/C "cmd/c del @path"

dir/ad/b/s E:\server\Remote\scan_bak\ |sort/r >e:\cmd\clean_scan_bak_kill.txt

for/f "tokens=*"%%i in (E:\cmd\clean_scan_bak_kill.txt) do rd "%%i"

Del E:\cmd\clean_scan_bak_kill.txt


echo Completion time:%date%_%time% >> E:\cmd\clean_scan_bak_log.txt


Then set the task schedule

View the log file with the following contents:

"#############################"

Start Time: 2015/09/21 Monday _ 0:00:00.74

completion time: 2015/09/21-Monday _ 1:13:44.66


This article is from the "Falling Star" blog, make sure to keep this source http://xiao987334176.blog.51cto.com/2202382/1697134

Windows automatically deletes files for 7 days

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.