|
xg19760104
新手上路

积分 6
发帖 2
注册 2007-1-14 来自 广州市
状态 离线
|
『楼 主』:
文件生成后100天自动删除指定文件,不能在垃圾桶里
使用 LLM 解释/回答一下
因工作需要,有大量的电脑在生成指定文件后100天要手动删除,老是有的机子不记的删,那位高人指点一下,文件记时删除,但不能给杀毒软件当病毒杀了
Due to work needs, there are a large number of computers that need to manually delete specified files 100 days after they are generated. There are always some machines that forget to delete them. Can any expert give some advice? Files are timed to be deleted, but they should not be regarded as viruses by the antivirus software.
|
|
2007-1-14 22:24 |
|
|
tghksj
社区乞丐
此图片另存后死机
积分 -49
发帖 90
注册 2006-12-2
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
问题的关键在于判断,今天的100天前是什么日期.
关系到日期个位和十位28,29,30,31进,去0的判断,百位12进,去0的判断
我感觉这个关键点不是用批处理能够轻松实现的.
The key to the problem is to judge what the date was 100 days ago today. It is related to the judgment of carrying over and removing zeros for the units and tens digits like 28, 29, 30, 31, and for the hundreds digit like 12 carrying over and removing zeros. I feel that this key point cannot be easily realized with batch processing.
|

我的网络笔记本.[color=Red]非联系本人请勿访问![/color]http://w.vicp.net[img]http://zhenlove.com.cn/cndos/fileup/files/QM2.jpg[/img] |
|
2007-1-14 23:55 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
还有平年闰年的判断,思路虽然简单,但是代码将会十分烦琐。
There is also the judgment of common years and leap years. Although the idea is simple, the code will be very cumbersome.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-15 00:13 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
一个更直接的办法是:
每三个月运行一次!
schtasks /create /tn "My App" /tr "你要执行的程序的全路经" /sc monthly /mo 3
A more direct way is:
Run it every three months!
schtasks /create /tn "My App" /tr "Full path of the program you want to execute" /sc monthly /mo 3
|
|
2007-1-15 00:14 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
2,3 楼
看代码
@echo off
setlocal enabledelayedexpansion
set dy=%date:~0,4%
set dm=%date:~5,2%
set dd=%date:~8,2%
echo %dy%-%dm%-%dd%
echo 计算一百天后的日期.
echo.
pause>nul
rem 先检查日期dd是否在以下条件(3-12),一二月份特殊考虑!
rem 同时默认的是dy年份为平年,最后才考虑闰年.
rem 所以只要在最后dd上加一就可以了!
for %%i in (3,5,7,8,10,12) do (
rem Check Odd Month(单数月).
if "%dm%" equ "%%i" (
set /a dm+=3
set /a dd+=8
rem 这时候,dm已经是双月份了.
goto :checkdd
)
)
rem Check Even Month(双数月).
for %%j in (4,6,9,11) do (
if "%dm%" equ "%%j" (
set /a dm+=3
set /a dd+=9
rem 这时候,dm已经是单月份了.
goto :checkdd
)
)
echo.
echo %dm%
pause
:jan-feb
rem 考虑一月和二月的情况.
if "%dm%" equ "1" (
set /a dm+=3
set /a dd+=10
goto :chckdd
)
if "%dm%" equ "2" (
set /a dm+=3
set /a dd+=10
goto :chckdd
)
:checkdd
rem 这时候,dm已经是双月份了.
rem Check Date is Great 30 or not.
if "%dd%" gtr "30" (
rem 比如6月24日就要改成7月2日
set dm%+=1 & set /a ddd=!dd!%-30
)
rem 这时,dm已经是单月份了.
rem Check Date is Great 31 or not.
if "%dd%" gtr "31" (
rem 比如7月24日就要改成8月2日.
set dm%+=1 set /a ddd=!dd!%-31
)
:checkYear
rem 检查平年还是闰年,只要不是平年"... neq 0",就将dd再加一.
set /a rmn=dy%\4
if "%rmn%" neq "0" (set /a dd+=1)
::Output the Result.
echo The day in 100 is: %dy%-%dm%-%dd%
schtasks /create /tn "DeleteTask" /m %dm% /tr "程序的全路径"
pause>nul
不能看到结果,请高手指正。
谢谢!
2, 3 floors
Look at the code
@echo off
setlocal enabledelayedexpansion
set dy=%date:~0,4%
set dm=%date:~5,2%
set dd=%date:~8,2%
echo %dy%-%dm%-%dd%
echo Calculate the date after 100 days.
echo.
pause>nul
rem First check if the date dd is in the following conditions (3-12), consider January and February specially!
rem Also, the default is that the year dy is a common year, and finally consider leap years.
rem So you can just add one to dd in the end!
for %%i in (3,5,7,8,10,12) do (
rem Check Odd Month (single month).
if "%dm%" equ "%%i" (
set /a dm+=3
set /a dd+=8
rem At this time, dm has become a double month.
goto :checkdd
)
)
rem Check Even Month (double month).
for %%j in (4,6,9,11) do (
if "%dm%" equ "%%j" (
set /a dm+=3
set /a dd+=9
rem At this time, dm has become a single month.
goto :checkdd
)
)
echo.
echo %dm%
pause
:jan-feb
rem Consider the situation of January and February.
if "%dm%" equ "1" (
set /a dm+=3
set /a dd+=10
goto :chckdd
)
if "%dm%" equ "2" (
set /a dm+=3
set /a dd+=10
goto :chckdd
)
:checkdd
rem At this time, dm has become a double month.
rem Check if the date is greater than 30.
if "%dd%" gtr "30" (
rem For example, June 24th should be changed to July 2nd
set dm%+=1 & set /a ddd=!dd!%-30
)
rem At this time, dm has become a single month.
rem Check if the date is greater than 31.
if "%dd%" gtr "31" (
rem For example, July 24th should be changed to August 2nd.
set dm%+=1 set /a ddd=!dd!%-31
)
:checkYear
rem Check common year or leap year, as long as it is not a common year "... neq 0", add one to dd.
set /a rmn=dy%\4
if "%rmn%" neq "0" (set /a dd+=1)
::Output the Result.
echo The day in 100 is: %dy%-%dm%-%dd%
schtasks /create /tn "DeleteTask" /m %dm% /tr "Full path of the program"
pause>nul
Can't see the result, please help correct it.
Thank you!
|
|
2007-1-15 00:18 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
闰年的计算方法出错了,正确的算法是:能被4整除,但是不能被400整除的年份不是闰年。比如,2000年是闰年,但是1900年就不是闰年;
set dm%+=1 的写法是错误的,没有这样的变量引用方式,并且,做算术运算的时候要加上开关 /a ;
另外,1月份没必要和2月份放在一起处理,和3、5等大月放在一起更合理一些。
The calculation method for leap years is incorrect. The correct algorithm is: A year that is divisible by 4 but not by 400 is not a leap year. For example, the year 2000 is a leap year, but the year 1900 is not a leap year;
The writing of `set dm%+=1` is incorrect. There is no such variable reference method, and when doing arithmetic operations, the switch `/a` should be added;
In addition, there is no need to handle January and February together. It is more reasonable to handle them together with large months like March, May, etc.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-15 00:33 |
|
|
lotus516
高级用户
    论坛上抢劫的
积分 551
发帖 246
注册 2006-9-21
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
版主namejm收藏的!
:: DateDel2.bat - 删除指定路径下指定日数以前修改的文件
:: Will Sort - 2005-9-2 - CMD@WinXP
:: 注意事项:参数%1指定日数,昨天为1,前天为2,依次类推
:: 参数%1指定文件路径,省略时将处理当前路径
:: 核心算法:Ritchie Lawrence, updated 2002-08-13. Version 1.1
::
@echo off & setlocal ENABLEEXTENSIONS
call :Date2Day %date:~0,10% sdays
set /a sdays-=%1
call :Day2Date %sdays% difdate
echo 将删除 %cd% 下 %difdate% 前的修改的以下文件:
for /r %2 %%f in (*.*) do if "%%~tf" LEQ "%difdate%" echo "%%f"
goto :EOF
:Date2Day
setlocal ENABLEEXTENSIONS
for /f "tokens=1-3 delims=/-, " %%a in ('echo/%1') do (
set yy=%%a & set mm=%%b & set dd=%%c
)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
endlocal&set %2=%j%&goto :EOF
:Day2Date
setlocal ENABLEEXTENSIONS
set /a i=%1,a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %2=%yy%-%mm%-%dd%&goto :EOF
后来搜了搜,这个代码是willsort的!!哈哈,原来代码第二行就写明了是willsort的!!
给两个链接 http://www.cn-dos.net/forum/viewthread.php?tid=23926&fpage=1&highlight=%E7%BA%AF%E6%95%B0%E5%AD%97&page=1
http://www.cn-dos.net/forum/viewthread.php?tid=16676
Last edited by lotus516 on 2007-1-15 at 01:15 AM ]
Moderator namejm's collection!
:: DateDel2.bat - Delete files modified before a specified number of days in the specified path
:: Will Sort - 2005-9-2 - CMD@WinXP
:: Notes: Parameter %1 specifies the number of days, where yesterday is 1, the day before yesterday is 2, and so on
:: Parameter %1 specifies the file path, and if omitted, the current path will be processed
:: Core algorithm: Ritchie Lawrence, updated 2002-08-13. Version 1.1
::
@echo off & setlocal ENABLEEXTENSIONS
call :Date2Day %date:~0,10% sdays
set /a sdays-=%1
call :Day2Date %sdays% difdate
echo The following files modified before %difdate% in %cd% will be deleted:
for /r %2 %%f in (*.*) do if "%%~tf" LEQ "%difdate%" echo "%%f"
goto :EOF
:Date2Day
setlocal ENABLEEXTENSIONS
for /f "tokens=1-3 delims=/-, " %%a in ('echo/%1') do (
set yy=%%a & set mm=%%b & set dd=%%c
)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
endlocal&set %2=%j%&goto :EOF
:Day2Date
setlocal ENABLEEXTENSIONS
set /a i=%1,a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %2=%yy%-%mm%-%dd%&goto :EOF
Later, I searched and found that this code is from willsort!! Haha, the second line of the original code clearly states it's from willsort!!
Here are two links http://www.cn-dos.net/forum/viewthread.php?tid=23926&fpage=1&highlight=%E7%BA%AF%E6%95%B0%E5%AD%97&page=1
http://www.cn-dos.net/forum/viewthread.php?tid=16676
Last edited by lotus516 on 2007-1-15 at 01:15 AM ]
|
|
2007-1-15 00:45 |
|
|
tghksj
社区乞丐
此图片另存后死机
积分 -49
发帖 90
注册 2006-12-2
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
!!!!!!!!!!!!!!!!!!!!疑willsort为神!!!!!!!!!!!!!!!!!!!!!
看的我只想哭....5555555555555555555555
Last edited by tghksj on 2007-1-14 at 12:11 PM ]
!!!!!!!!!!!!!!!!!!!!Willsort is regarded as a god!!!!!!!!!!!!!!!!!!!!!
It makes me just want to cry....5555555555555555555555
[[i] Last edited by tghksj on 2007-1-14 at 12:11 PM [/i]]
|

我的网络笔记本.[color=Red]非联系本人请勿访问![/color]http://w.vicp.net[img]http://zhenlove.com.cn/cndos/fileup/files/QM2.jpg[/img] |
|
2007-1-15 01:05 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
|
2007-1-15 05:45 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by namejm at 2007-1-14 11:33:
闰年的计算方法出错了,正确的算法是:能被4整除,但是不能被400整除的年份不是闰年。比如,2000年是闰年,但是1900年就不是闰年;
set ...
set ... 那里是粗心,谢谢了
但是一月和二月的问题是这样的
假设当前日期是一月,那么从一月到二月,是变化31天,而二月到三月十变化28天(平年);
假设当前日期是三月,那么从三月到四月十31天,好,程序没有逻辑错误;
但是从四月到五月,就是变化30天,那么,你说还能用 set 。。。+=28 吗?
所以,就不能把1月和3,5,7,8,10,12放在一起考虑 !
同样的道理,2月和4,6,9,11也不能放在一起。
故此,就1,2月另外考虑,并不是因为把他们写在一起,就是说他们有什么问题!
不知道大家的意见如何 ?
Originally posted by namejm at 2007-1-14 11:33:
The leap year calculation method is wrong. The correct algorithm is: A year that is divisible by 4 but not by 400 is not a leap year. For example, the year 2000 is a leap year, but the year 1900 is not a leap year;
set ...
The set... part was a carelessness, thank you
But the problem with January and February is like this
Suppose the current date is January, then from January to February, it changes by 31 days, and from February to March it changes by 28 days (in a common year);
Suppose the current date is March, then from March to April it is 31 days, okay, the program has no logical error;
But from April to May, it is 30 days, then, can you still use set... +=28?
So, you can't group January and March, May, July, August, October, December together!
By the same token, February and April, June, September, November can't be grouped together.
Therefore, only January and February are considered separately, not because grouping them together means they have any problem!
I don't know what everyone's opinion is?
|
|
2007-1-15 05:52 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
机器不允许把日期修改到1979年之前的!!
The machine does not allow modifying the date to before 1979!!
|
|
2007-1-15 05:54 |
|
|
scriptor
银牌会员
    
积分 1187
发帖 555
注册 2006-12-21
状态 离线
|
『第 12 楼』:
The latest code
使用 LLM 解释/回答一下
@echo off
{::setlocal enabledelayedexpansion It is no need to add in! }
set dy=%date:~0,4%
set dm=%date:~5,2%
set dd=%date:~8,2%
echo Today is : %dy%-%dm%-%dd%
echo 计算一百天后的日期.
echo.
pause>nul
rem 先检查日期dd是否在以下条件(3-12),一二月份特殊考虑!
rem 同时默认的是dy年份为平年,最后才考虑闰年.
rem 所以只要在最后dd上加一就可以了!
for %%i in (3,5,7,8,10,12) do (
rem Check Odd Month(单数月).
if %dm% equ %%i (
set /a dm+=3
set /a dd+=8
rem 这时候,dm已经是双月份了.
goto :checkdd
)
)
rem Check Even Month(双数月).
for %%j in (4,6,9,11) do (
if %dm% equ %%j (
set /a dm+=3
set /a dd+=9
rem 这时候,dm已经是单月份了.
goto :checkdd
)
)
::jan and feb
rem 考虑一月和二月的情况.
if %dm% equ 1 (
set /a dm+=3
set /a dd+=10
goto :checkdd
)
if %dm% equ 2 (
set /a dm+=3
set /a dd+=10
goto :checkdd
)
:checkdd
rem 这时候,dm已经是双月份了.
rem Check Date is Great 30 or not.
if %dd% gtr 30 (
rem 比如6月24日就要改成7月2日
set /a dm+=1
set /a ddd=%dd%-30
)
rem 这时,dm已经是单月份了.
rem Check Date is Great 31 or not.
if %dd% gtr 31 (
rem 比如7月24日就要改成8月2日.
set /a dm+=1
set /a ddd=%dd%-31
)
:checkYear {Here, Be careful , the code is not the same with the former I writed!}
rem 检查平年还是闰年,只要不是平年"... equ 0",就将dd再加一.
set /a rmn=dy%4
set /a rmnn=dy%400
if %rmn% neq 0 (echo This year is not leap year!)
if %rmn% equ 0 (
if %rmnn% equ 0 (
echo This year is leap year!
set /a dd+=1
)
)
::Output the Result.
echo The day after 100 days is: %dy%-%dm%-%dd%!
:: "Attach any code executable here!"
pause>nul
Last edited by scriptor on 2007-1-14 at 05:39 PM ]
@echo off
{::setlocal enabledelayedexpansion It is no need to add in! }
set dy=%date:~0,4%
set dm=%date:~5,2%
set dd=%date:~8,2%
echo Today is : %dy%-%dm%-%dd%
echo Calculate the date after 100 days.
echo.
pause>nul
rem First check if the date dd is in the following conditions (3-12), consider January and February specially!
rem Also, the default is that the year dy is a common year, and finally consider leap years.
rem So just add one to dd at the end!
for %%i in (3,5,7,8,10,12) do (
rem Check Odd Month (single month).
if %dm% equ %%i (
set /a dm+=3
set /a dd+=8
rem At this time, dm has become a double month.
goto :checkdd
)
)
rem Check Even Month (double month).
for %%j in (4,6,9,11) do (
if %dm% equ %%j (
set /a dm+=3
set /a dd+=9
rem At this time, dm has become a single month.
goto :checkdd
)
)
::jan and feb
rem Consider the situation of January and February.
if %dm% equ 1 (
set /a dm+=3
set /a dd+=10
goto :checkdd
)
if %dm% equ 2 (
set /a dm+=3
set /a dd+=10
goto :checkdd
)
:checkdd
rem At this time, dm has become a double month.
rem Check if the date is greater than 30.
if %dd% gtr 30 (
rem For example, June 24th should be changed to July 2nd.
set /a dm+=1
set /a ddd=%dd%-30
)
rem At this time, dm has become a single month.
rem Check if the date is greater than 31.
if %dd% gtr 31 (
rem For example, July 24th should be changed to August 2nd.
set /a dm+=1
set /a ddd=%dd%-31
)
:checkYear {Here, Be careful , the code is not the same with the former I writed!}
rem Check if it is a common year or a leap year. As long as it is not a common year "... equ 0", add one to dd.
set /a rmn=dy%4
set /a rmnn=dy%400
if %rmn% neq 0 (echo This year is not leap year!)
if %rmn% equ 0 (
if %rmnn% equ 0 (
echo This year is leap year!
set /a dd+=1
)
)
::Output the Result.
echo The day after 100 days is: %dy%-%dm%-%dd%!
:: "Attach any code executable here!"
pause>nul
|
|
2007-1-15 06:36 |
|
|
xiaoqiangzx
初级用户
 
积分 34
发帖 12
注册 2007-1-16
状态 离线
|
『第 13 楼』:
dos简单就好!!!
使用 LLM 解释/回答一下
首先我非常敬佩大家的专业知识和学习热情~~
小弟我不才有句话想说
dos 不象 c++ 能否简单就好~~~
别搞的很高深似的 要平民化!!!!
楼主的是:文件生成后100天自动删除指定文件,对不对?
比如:要del c盘的临时文件夹
只要建立个xxx.bat文件
内容:
@echo off
del /f /s /q %systemdrive%\*.tmp
然后把这个bat放在系统自带定时任务中设置为每100天运行一次即可以拉~~
....................
First of all, I very much admire everyone's professional knowledge and enthusiasm for learning.
I, the younger brother, have something to say. DOS is not like C++, can it be simple? Don't make it seem very profound, it should be popular!
The landlord's statement is: After the file is generated, the specified file is automatically deleted after 100 days, right?
For example: To delete the temporary folder on drive C. Just create an xxx.bat file. The content is:
@echo off
del /f /s /q %systemdrive%\*.tmp
Then put this bat in the system's built-in scheduled tasks and set it to run every 100 days, and that's it...
|

小强网志欢迎你 |
|
2007-1-16 09:47 |
|
|
xg19760104
新手上路

积分 6
发帖 2
注册 2007-1-14 来自 广州市
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
收到,非常有启发!谢谢 各位!
Got it, very inspiring! Thank you everyone!
|
|
2007-1-18 14:48 |
|
|
timlee
新手上路

积分 16
发帖 8
注册 2007-1-20
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
13楼的思路很有启发,能简单的何必搞得太复杂。
The idea on the 13th floor is very inspiring. Why make it too complicated when it can be simple?
|
|
2007-1-20 11:55 |
|
|