![]() |
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-09-29 13:21 |
47,813 topics / 349,918 posts / today 0 new / 48,278 members |
| DOS批处理 & 脚本技术(批处理室) » [Closed] Batch script to automatically delete file directories older than N days |
| Printable Version 3,708 / 35 |
| Floor31 yuehong | Posted 2008-10-21 18:38 |
| 初级用户 Posts 37 Credits 64 | |
Originally posted by dddyjq1 at 2008-10-21 01:15 AM: Still not working under 2000 Appears: There should not be "at this time. There should not be "at this time. There should not be "at this time. There should not be "at this time. There should not be "at this time. |
|
| Floor32 terse | Posted 2008-10-21 19:48 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
My situation here:
Attachments aaa.gif (4.97 KiB) |
|
| Floor33 yuehong | Posted 2008-10-21 22:09 |
| 初级用户 Posts 37 Credits 64 | |
Originally posted by terse at 2008-10-21 07:48 PM: |
|
| Floor34 terse | Posted 2008-10-21 23:13 |
| 银牌会员 Posts 946 Credits 2,404 | |
Originally posted by yuehong at 2008-10-21 22:09: Actually, this is what I gave you on floor 20. You actually bumped it up here. To delete files, you need to first dir /a-d /b, then judge the time, and then del |
|
| Floor35 aphasia | Posted 2008-10-27 16:18 |
| 新手上路 Posts 1 Credits 1 | |
|
Very good.
|
|
| Floor36 qwertl | Posted 2008-11-03 11:56 |
| 中级用户 Posts 243 Credits 461 | |
|
In Windows 2000, for the code:
First, for the part of handling `FileDate`: The original code for setting `FileDate` in Windows 2000: ``` set FileDate=08-10-22 17:56 set FileDate=!FileDate:-=! set FileDate=!FileDate:~0,8! if !FileDate! LSS 20081023 (echo ....) ``` Since in Windows 2000, the way of handling date format might have some differences, but the basic operations of replacing `-` and taking the first 8 characters are similar. Just make sure the date comparison is correct according to the actual situation. For the part related to `MyDel.vbs`: The code for creating and running the VBScript is the same in terms of logic. It calculates the date minus 11 days and then gets the formatted date string. For the part of getting the file date and comparing: The line `set FileDate=%%~ta` gets the file date and time. In Windows 2000, the format of `%%~ta` might be a bit different from XP and 2003, but the subsequent operations of replacing `-` and taking the first 8 characters are the same. Then comparing `!FileDate!` with `%DateFlag%` is the same logic. The overall translated code remains as the original code structure but adjusted for the Windows 2000 environment considerations as described above. The translated text of the entire code block as follows: In win2003 it works normally to delete set FileDate=2008-10-27 22:20 set FileDate=!FileDate:-=! set FileDate=!FileDate:~0,8! if !FileDate! LSS 20081018 (echo ....) How to modify this code under win2000? set FileDate=08-10-22 17:56 set FileDate=!FileDate:-=! set FileDate=!FileDate:~0,8! if !FileDate! LSS 20081023 (echo ....) set desfolder=e:\rardata setlocal enabledelayedexpansion >"%tmp%\MyDel.vbs" echo dt=date()-11 >>"%tmp%\MyDel.vbs" echo s=right(year(dt),4) ^& right("0" ^& month(dt),2) ^& right("0" ^& day(dt),2) >>"%tmp%\MyDel.vbs" echo wscript.echo s for /f %%a in ('cscript /nologo "%tmp%\MyDel.vbs"') do set DateFlag=%%a echo %DateFlag% pause for /f "tokens=*" %%a in ('dir /s /b /a-d "%desfolder%"') do ( set FileDate=%%~ta The file date obtained here is different from that in xp and 2003. set FileDate=!FileDate:-=! set FileDate=!FileDate:~0,8! if !FileDate! lss %DateFlag% ( echo "%%a" ) ) pause |
|
| Prev 1 2 3 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |