In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use batch processing to delete files before a specific time. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Using the for command to read the result of dir / tc / Omurd / a can be divided into four paragraphs, the first two paragraphs are the date and time, the third paragraph is the directory or file size, and the fourth paragraph is the file name or directory name. Then compare paragraphs 1 and 2 with the required time to decide whether to delete the file or not
@ echo off rem cd / d f:\ temp rem mDateTime format: yyymmddHHmm set mDateTime=200608161907 for / f "skip=4 tokens=1,2 3 proc set aDate=%1 set aTime=%2 set aType=%3 set aFile=%4 set aDatetime=%aDate:~0,4%%aDate:~5,2%%aDate:~8,2%%aTime:~0,2%%aTime:~3,2% if 4* delims= "% I in ('dir / a /-c / tc / OMID') do call: proc% I% j% k% l goto end: proc set aDate=%1 set aTime=%2 set aType=%3 set aFile=%4 set aDatetime=%aDate:~0,4%%aDate:~5,2%%aDate:~8,2%%aTime:~0,2%%aTime:~3,2% if / I"% aDateTime% "lss"% mDateTime% "(if NOT"% aType% "=" DIR "attrib"% aFile% " "- r-h-s & & del"% aFile% "): end
But there will be some problems above, mainly because if can't compare large numbers. 200608161907 is too big for if. We can compare the date first, and then the time, but there are more if statements, so let's compromise and use two-digit years:
Rem mDateTime format: ymmddHHmm
Set mDateTime=0608161907
……
Set aDatetime=%aDate:~2,2%%aDate:~5,2%%aDate:~8,2%%aTime:~0,2%%aTime:~3,2%
Windows2003 has a command Forfiles, such as:
Forfiles / D-30 / C "cmd / c echo @ fname is from 30 days ago. 2003 Forfiles.exe files can be copied and used under 2000.
In addition, it is easier to keep the last n files, for example, the last 30 bak files:
For / f "skip=30"% I in ('dir * .bak / tc / omurd / b') do del% I
In batch processing, change% I to% I
Thank you for reading! On "how to use batch processing to delete files before a specific time" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.