![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-13 00:42 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » Asking for "a bat for regularly cleaning folders" (waiting for the 2nd day) |
| Printable Version 2,891 / 16 |
| Floor1 sj2009 | Posted 2009-12-15 14:46 |
| 新手上路 Posts 10 Credits 10 | |
|
Want to make a scheduled task to regularly clean up the materials in d:\Video Recordings once a month. But don't know how to write such a BAT file. Please help from kind - hearted people.
[ Last edited by sj2009 on 2009 - 12 - 16 at 16:56 ] |
|
| Floor2 Hanyeguxing | Posted 2009-12-15 15:12 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
How would you clean up?
If you want to delete all mpg files under the D root directory (excluding subdirectories) on this day of each month, you can: [ Last edited by Hanyeguxing on 2009-12-15 at 15:25 ] |
|
| Floor3 hanxiaofeng888 | Posted 2009-12-15 22:14 |
| 新手上路 Posts 4 Credits 5 | |
|
If you only make a BAT to clean files every month, then this BAT must be kept on all the time.
You can do it like this. Save the following code as a BAT, add it to the task scheduler, and let it start once a month. Is this very concise? Hehe. del /q d:\Video Recording Materials\*.* The above can only delete all files under d:\Video Recording Materials\, and cannot delete folders and files in subdirectories. del /q /s d:\Video Recording Materials\*.* Delete all files under d:\Video Recording Materials\ and all files in subdirectories, but cannot delete folders. |
|
| Floor4 sj2009 | Posted 2009-12-16 09:05 |
| 新手上路 Posts 10 Credits 10 | |
|
Reply to the expert in floor 2, I didn't express it accurately enough, sorry.
Actually, the BAT file I want to write is to make a scheduled task, Regularly clean up the video files *.* in d:\Video Recordings\ every month, For example, now it's December 2009, I need to clean up the video files of October and November before, please write it again |
|
| Floor5 sj2009 | Posted 2009-12-16 09:06 |
| 新手上路 Posts 10 Credits 10 | |
|
Thanks, brother on the 3rd floor.
|
|
| Floor6 sj2009 | Posted 2009-12-16 12:56 |
| 新手上路 Posts 10 Credits 10 | |
| Floor7 qinchun36 | Posted 2009-12-16 16:02 |
| 高级用户 Posts 400 Credits 609 | |
|
Please first right-click and check the properties of your files.
Are you going to clean up based on "Creation Time" or "Modification Time" If it's the latter, I can help with that. If it's the former, using a bat would need to call WMIC, which is too cumbersome for me... |
|
| Floor8 sj2009 | Posted 2009-12-16 16:04 |
| 新手上路 Posts 10 Credits 10 | |
|
Returning to LS, the basis for cleaning is "creation time"
|
|
| Floor9 sj2009 | Posted 2009-12-16 16:05 |
| 新手上路 Posts 10 Credits 10 | |
|
Ask how to clean up folders named by dates
Actually, what I want to write is a BAT file to make a scheduled task, regularly clean up the video files in the directory d:\Video Recordings\20091201\ every 2 months, 20091201 is a folder named by date, just like now it's December 2009, I need to clean up the video files from October and November before that |
|
| Floor10 sj2009 | Posted 2009-12-16 16:14 |
| 新手上路 Posts 10 Credits 10 | |
|
http://www.cn-dos.net/forum/viewthread.php?tid=16676&fpage=1&highlight=WINDOWS+AND+DOS+command+delete+files+before+N+days&page=1
I have also seen this here, but I can't solve it by myself |
|
| Floor11 qinchun36 | Posted 2009-12-16 17:11 |
| 高级用户 Posts 400 Credits 609 | |
|
Oh my god, I'm exhausted. I wrote one for you. Don't rush to run it, let me explain first.
1. Don't post repeatedly. This behavior is very despised. 2. Only one folder can be handled each time, so you need to set it each time. Modify this code. Do you know wildcards? Like set files=d:\Video Recording Materials\20091201\*.* or change it to *.rmvb 3. Remember that this processes the 'creation date', please understand it carefully. 4. First confirm that your machine has WMIC installed. The specific method is to execute wmic in the command line window. Only after installation can this batch file be run. |
|
| Floor12 Hanyeguxing | Posted 2009-12-16 19:14 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
First of all, similar to how often to run the batch processing, it is set in the task schedule.
Run this batch processing in the task schedule: Among them: 1. Path refers to the directory to be operated, for example d:\video recording materials 2. Time is the comparison time. For example, taking October 12, 2009 09:13 as the dividing point, it is written as 200910120913, where: time1 is the start of the time period, time2 is the end of the time period, and this batch processing will delete all files created between this time period. 3. This batch processing can only process one directory (folder) at a time and does not process its subdirectories (folders). 4. This batch processing depends on the output format of dir, so please test the dir command output before running to see if it meets the requirements of this batch processing. Run dir "path" /a:-d /t:c in cmd See if the output is like the following example. Volume in drive C has no label. Volume Serial Number is 303A-5C0B Directory of C:\Documents and Settings\Hanye Guxing 2009-10-12 09:13 2,883,584 NTUSER.DAT 2009-10-12 09:13 24,576 ntuser.dat.LOG 2009-10-12 09:13 178 ntuser.ini 2009-10-12 21:48 976 ntuser.pol 4 File(s) 2,909,314 bytes 0 Dir(s) 12,642,504,704 bytes free If you only want to delete files before a certain time point, you can write it like this: [ Last edited by Hanyeguxing on 2009-12-16 at 19:54 ] |
|
| Floor13 Hanyeguxing | Posted 2009-12-16 20:39 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
If you want to delete files from the previous few months, you can write it like this:
Among them, set n= sets the length of the month. For example, if it is currently December, and you want to delete files from the previous 5 months, then set set n=5, that is, the months to be checked are July, August, September, October, November. Note that n must be a number between 1 and 12. [ Last edited by Hanyeguxing on 2009-12-16 at 20:59 ] |
|
| Floor14 hanxiaofeng888 | Posted 2009-12-16 20:59 |
| 新手上路 Posts 4 Credits 5 | |
|
The person upstairs is amazing. Using it so cleverly and concisely. Learned it.
|
|
| Floor15 sj2009 | Posted 2009-12-17 08:51 |
| 新手上路 Posts 10 Credits 10 | |
|
Thank you very much: qinchun36 and Hanyeguxing;
I will study seriously |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |