![]() |
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-07 12:50 |
48,040 topics / 350,125 posts / today 0 new / 48,252 members |
| DOS批处理 & 脚本技术(批处理室) » Seek to delete files based on time: delete files with a creation date greater than 1 day |
| Printable Version 1,632 / 13 |
| Floor1 yhshiro | Posted 2008-02-10 03:11 |
| 初级用户 Posts 59 Credits 130 | |
|
As the title says: I want to delete files in a certain disk whose creation date is more than one day. ... As long as the files are more than one day, delete them regardless of the format...
Can someone make a batch file for me to use?? ───────────────── Moderation Record ───────────────── Performed by: HAT Operation: Added search keywords to the post title Description: The original title "Ask for a batch file to delete files according to time" is not conducive to forum search ───────────────── Moderation Record ───────────────── [ Last edited by HAT on 2008-9-27 at 10:20 ] |
|
| Floor2 terse | Posted 2008-02-10 03:33 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
A few days ago I posted on the forum saying the test was not successful, you take a look
@echo off SET/p TT=Enter the number of days: SET/p PH=Enter the path: set p1=%date:~0,4% set p2=%date:~5,2% set p3=%date:~8,2% setlocal enabledelayedexpansion for /l %%a in (1,1,3) do ( for /f "delims=0 tokens=*" %%i in ("!p%%a!") do set p%%a=%%i ) if %p3% gtr %TT% goto ppp :nxt set/a p2-=1 if %p2% equ 0 set/a p1-=1&&set p2=12 SET/a PN1=%p1%%%4 set PN2=28 if %PN1% EQU 0 set pN2=29 for /f "tokens=%p2%" %%i in ("31 %pN2% 31 30 31 30 31 31 30 31 30 31") do set/a p3=%p3%+%%i if %p3% leq %tt% goto nxt :ppp set/a p3=%p3%-%tt% set p2=0%p2% set p2=%p2:~-2,2% set p3=0%p3% set p3=%p3:~-2,2% for %%i in ("%PH%\*") do set t=%%~ti &&call :loop "%%~fi" pause goto :eof :loop if not "%~1" == "%~f0" ( IF %p1%%p2%%p3% gtr %t:~0,4%%t:~5,2%%t:~8,2% echo del "%~1" ) |
|
| Floor3 yhshiro | Posted 2008-02-11 00:11 |
| 初级用户 Posts 59 Credits 130 | |
|
No, it can be displayed to delete, but it can't be deleted
|
|
| Floor4 terse | Posted 2008-02-11 01:51 |
| 银牌会员 Posts 946 Credits 2,404 | |
Originally posted by yhshiro at 2008-2-11 00:11: Change echo del "%~1" to del "%~1" |
|
| Floor5 yhshiro | Posted 2008-02-11 20:27 |
| 初级用户 Posts 59 Credits 130 | |
|
Still not working....Now it doesn't even display, it's completely done./.
|
|
| Floor6 terse | Posted 2008-02-11 20:40 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
What content was displayed when it could be shown before? Can you post it?
|
|
| Floor7 yhshiro | Posted 2008-02-11 21:02 |
| 初级用户 Posts 59 Credits 130 | |
|
It shows that the file name to be deleted
del "f:\XXXXXXX.XX" That's the kind of content |
|
| Floor8 yhshiro | Posted 2008-02-11 21:05 |
| 初级用户 Posts 59 Credits 130 | |
|
Now it's okay, you can use... But it can only delete files under the specified drive, not files inside folders
|
|
| Floor9 terse | Posted 2008-02-11 21:17 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
How about this?
Originally posted by yhshiro at 2008-2-11 21:05: @echo off :st cls SET/p TT=Enter the number of days: SET/p PH=Enter the path: if "%tt%" =="" echo The number of days cannot be empty&pause&goto st if "%ph%" =="" echo The path cannot be empty &pause&goto st echo %tt%|findstr "^*$">nul&&goto ys||echo The number of days can only be 1-9&pause&goto st :ys set p1=%date:~0,4% set p2=%date:~5,2% set p3=%date:~8,2% setlocal enabledelayedexpansion for /l %%a in (1,1,3) do ( for /f "delims=0 tokens=*" %%i in ("!p%%a!") do set p%%a=%%i ) if %p3% gtr %TT% goto ppp :nxt set/a p2-=1 if %p2% equ 0 set/a p1-=1&&set p2=12 SET/a PN1=%p1%%%4 set PN2=28 if %PN1% EQU 0 set pN2=29 for /f "tokens=%p2%" %%i in ("31 %pN2% 31 30 31 30 31 31 30 31 30 31") do set/a p3=%p3%+%%i if %p3% leq %tt% goto nxt :ppp set/a p3=%p3%-%tt% set p2=0%p2% set p2=%p2:~-2,2% set p3=0%p3% set p3=%p3:~-2,2% for /r "%ph%" %%i in (*.*) do call :loop "%%~fi" pause goto :eof :loop if not "%~1" == "%~f0" ( IF %p1%%p2%%p3% gtr %t:~0,4%%t:~5,2%%t:~8,2% del %1 ) [ Last edited by terse on 2008-2-11 at 09:28 PM ] |
|
| Floor10 yhshiro | Posted 2008-02-11 21:26 |
| 初级用户 Posts 59 Credits 130 | |
|
Please provide the batch script code for deleting all files in the f:\ directory that are older than 1 day, including those in subfolders. The following is a simple batch script to achieve this function:
```batch @echo off forfiles /p "f:\" /s /m *.* /d -1 /c "cmd /c del /q @path" ``` Explanation: - `forfiles`: A command used to find files that meet specific time conditions. - `/p "f:\"`: Specify the target directory as the f drive root directory. - `/s`: Recursively search subdirectories. - `/m *.*`: Match all files. - `/d -1`: Find files older than 1 day. - `/c "cmd /c del /q @path"`: For each found file, execute the `del /q` command to delete the file quietly. |
|
| Floor11 yhshiro | Posted 2008-02-11 21:44 |
| 初级用户 Posts 59 Credits 130 | |
|
The filename, directory name, or volume label syntax is incorrect.
意思是:文件名、目录名或卷标语法不正确。 |
|
| Floor12 terse | Posted 2008-02-11 21:45 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
@echo off
SET TT=1 set p1=%date:~0,4% set p2=%date:~5,2% set p3=%date:~8,2% setlocal enabledelayedexpansion for /l %%a in (1,1,3) do ( for /f "delims=0 tokens=*" %%i in ("!p%%a!") do set p%%a=%%i ) if %p3% gtr %TT% goto ppp :nxt set/a p2-=1 if %p2% equ 0 set/a p1-=1&&set p2=12 SET/a PN1=%p1%%%4 set PN2=28 if %PN1% EQU 0 set pN2=29 for /f "tokens=%p2%" %%i in ("31 %pN2% 31 30 31 30 31 31 30 31 30 31") do set/a p3=%p3%+%%i if %p3% leq %tt% goto nxt :ppp set/a p3=%p3%-%tt% set p2=0%p2% set p2=%p2:~-2,2% set p3=0%p3% set p3=%p3:~-2,2% for /r "f:\" %%i in (*.*) do set t=%%~ti &&call :loop "%%~fi" pause goto :eof :loop if not "%~1" == "%~f0" ( IF %p1%%p2%%p3% gtr %t:~0,4%%t:~5,2%%t:~8,2% del %1 ) |
|
| Floor13 yhshiro | Posted 2008-02-11 21:48 |
| 初级用户 Posts 59 Credits 130 | |
|
Thanks, it's already working~~~
Thanks a lot |
|
| Floor14 zcnvnv | Posted 2008-02-12 18:18 |
| 初级用户 Posts 36 Credits 114 | |
|
Use for to get the date and file name of dir, judge, delete the ones that should be deleted with del file name, and pass the ones that should not be deleted.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |