![]() |
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-23 12:57 |
47,812 topics / 349,917 posts / today 0 new / 48,273 members |
| DOS批处理 & 脚本技术(批处理室) » (Closed) How to delete files older than N days in the DOS command line under WINDOWS |
| Printable Version 29,269 / 39 |
| Floor16 Climbing | Posted 2005-08-26 20:17 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Re Will Sort:
Hehe, the reason I only used for /f is that, to be honest, I never really understood many of the usages of the for command. At least, I never quite understood what for /r meant. But just now I tried it myself, and finally understood it a little, so that command of mine can be changed to: for /r %dst% %%f in (*.*) do if %%~tf LSS %1 del /f /q %%f && echo delete %%f Hehe, the reason is just that simple. I'm not as persistent in pursuing technology as brother Wil is. My goal is just to get the job done. Honestly, I sincerely admire brother Wil's batch-writing skills, but I feel I'll never reach that level, and I think brother Wil's batch skills are more than enough, but they really aren't easy for people to understand. As for the batch file in the post above yours, I didn't really understand it until I was replying to this post. |
|
| Floor17 zybird | Posted 2005-08-29 13:40 |
| 中级用户 Posts 53 Credits 240 | |
|
A few days ago I wrote two small programs for under DOS, which just happen to be able to accomplish this task.
The batch file content is like this: ****************************************************** @echo off rem ============================================ rem The purpose of this batch file is to delete all files in d:\datafile rem whose last modification time was earlier than 7 days ago (not including 7 days) rem (including files in all subdirectories) rem ============================================ rem ============================================ rem Get the date from 7 days ago rem If today is August 25, then the date 7 days ago is August 18 rem ============================================ GetInfo.COM /d:-7 set theDay=%year%-%mon%-%day% rem ============================================ rem This searches in D:\datafile中搜索8天前(含8 for files modified 8 days ago (including 8 days) rem that is, files modified on August 17 and earlier rem ============================================ attrib/s d:\datafile\*.* -h -r -s :Loop dirt.com /d:-%theDay% d:\datafile\*.* /q if %DirtRet%==Fail goto end del %FPath%\%FName% goto Loop :end ****************************************************** The DirT.com and GetInfo.com in it can be downloaded from http://www.13886.com/soft//, In DOS under win2000, the del command seems to have a parameter that lets you delete files without user confirmation; you can add that parameter to del %FPath%\%FName% [ Last edited by zybird on 2006-5-6 at 13:38 ] |
|
| Floor18 Climbing | Posted 2005-08-29 17:02 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
These two commands are pretty interesting, and quite useful too. Could you upload them here directly as attachments? That website can't be accessed anymore.
|
|
| Floor19 zybird | Posted 2005-08-29 18:47 |
| 中级用户 Posts 53 Credits 240 | |
Originally posted by Climbing at 2005-8-29 05:02 PM: On ys168, for some reason, it always becomes impossible to download, so now I've uploaded them here. If you have any questions or run into any errors during use, please tell me! Thanks! Getinfo.com and dirt.com can now be downloaded directly from the website below!! http://www.13886.com/soft/ [ Last edited by zybird on 2006-5-6 at 13:37 ] |
|
| Floor20 Climbing | Posted 2005-08-29 23:47 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Thanks, friend zybird. Were both of these commands developed with Qbasic?
|
|
| Floor21 zybird | Posted 2005-08-30 13:10 |
| 中级用户 Posts 53 Credits 240 | |
|
You're welcome!
This was written with tc++ 3.0 |
|
| Floor22 willsort | Posted 2005-09-02 15:25 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re All:
Because of personal reasons, I hadn't been on the forum for a week, and I found that quite a lot had changed! Now I am attaching the set /a method mentioned in item 1 of the problem-solving ideas in post 9 for calculating date differences. As for third-party programs, zybird's program is already very good; my respects to brother zybird. |
|
| Floor23 smileseeker | Posted 2005-10-17 19:56 |
| 中级用户 Posts 83 Credits 316 | |
|
Question for all you experts,
why is it that under the win2000 command line, environment variables like year mon day etc. cannot be displayed? D:\MULTIT~1\Getinfo>getinfo /d:-2 D:\MULTIT~1\Getinfo>echo %day% %day% |
|
| Floor24 smileseeker | Posted 2005-10-17 20:10 |
| 中级用户 Posts 83 Credits 316 | |
|
Quote:
Originally posted by Climbing at 2005-8-25 17:38: for /f "tokens=*" %f in ('dir /b/s' do @if %~tf LSS 2005-08-17 echo %~tf %f Awesome!!! Agreed!!! ![]() [ Last edited by smileseeker on 2005-10-17 at 20:12 ] |
|
| Floor25 zybird | Posted 2005-10-19 21:10 |
| 中级用户 Posts 53 Credits 240 | |
|
getinfo.com currently still cannot modify environment variables in cmd.exe; cmd.exe is not the same as dos
|
|
| Floor26 tianlei | Posted 2005-11-10 00:20 |
| 新手上路 Posts 5 Credits 10 From 中国杭州 | |
|
“for /f "tokens=*" %f in ('dir /b/s') do @if %~tf LSS 2005-08-17 echo %~tf %f”
What does the “%” in there represent? Could someone please explain? |
|
| Floor27 tyh | Posted 2007-06-08 09:35 |
| 初级用户 Posts 43 Credits 80 | |
|
Damn, I can't understand it```` I'm dizzy.
|
|
| Floor28 ningshaody | Posted 2007-10-10 10:23 |
| 新手上路 Posts 1 Credits 2 | |
|
The method above works well for deleting files. Can it avoid deleting folders?
|
|
| Floor29 ribood | Posted 2007-10-10 19:24 |
| 新手上路 Posts 4 Credits 12 | |
|
A newbie asking: if the OS regional setting is English and date displays as 10/10/2007 wed, how should the batch file be written??
|
|
| Floor30 lzmuhioin | Posted 2007-10-12 09:54 |
| 初级用户 Posts 24 Credits 51 | |
|
Expert indeed,,, so awesome... learned a lot
|
|
| Prev 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |