中国DOS联盟论坛

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-29 08:05
47,816 topics / 349,916 posts / today 0 new / 48,265 members
DOS批处理 & 脚本技术(批处理室) » Automatically delete the specified file 100 days after the file is generated, and not in the trash can
Printable Version  5,479 / 21
Floor1 xg19760104 Posted 2007-01-14 22:24
新手上路 Posts 2 Credits 6 From 广州市
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.
Floor2 tghksj Posted 2007-01-14 23:55
社区乞丐 Posts 90 Credits -49
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.
Floor3 namejm Posted 2007-01-15 00:13
荣誉版主 Posts 1,737 Credits 5,226 From 成都
There is also the judgment of common years and leap years. Although the idea is simple, the code will be very cumbersome.
Floor4 scriptor Posted 2007-01-15 00:14
银牌会员 Posts 555 Credits 1,187
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
Floor5 scriptor Posted 2007-01-15 00:18
银牌会员 Posts 555 Credits 1,187
2, 3 floors

Look at the code



Can't see the result, please help correct it.
Thank you!
Floor6 namejm Posted 2007-01-15 00:33
荣誉版主 Posts 1,737 Credits 5,226 From 成都
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.
Floor7 lotus516 Posted 2007-01-15 00:45
高级用户 Posts 246 Credits 551
Moderator namejm's collection!

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 linkshttp://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 ]
Floor8 tghksj Posted 2007-01-15 01:05
社区乞丐 Posts 90 Credits -49
!!!!!!!!!!!!!!!!!!!!Willsort is regarded as a god!!!!!!!!!!!!!!!!!!!!!

It makes me just want to cry....5555555555555555555555

[ Last edited by tghksj on 2007-1-14 at 12:11 PM ]
Floor9 scriptor Posted 2007-01-15 05:45
银牌会员 Posts 555 Credits 1,187
Floor10 scriptor Posted 2007-01-15 05:52
银牌会员 Posts 555 Credits 1,187
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?
Floor11 scriptor Posted 2007-01-15 05:54
银牌会员 Posts 555 Credits 1,187
The machine does not allow modifying the date to before 1979!!
Floor12 scriptor Posted 2007-01-15 06:36
银牌会员 Posts 555 Credits 1,187


@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

Floor13 xiaoqiangzx Posted 2007-01-16 09:47
初级用户 Posts 12 Credits 34
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...
Floor14 xg19760104 Posted 2007-01-18 14:48
新手上路 Posts 2 Credits 6 From 广州市
Got it, very inspiring! Thank you everyone!
Floor15 timlee Posted 2007-01-20 11:55
新手上路 Posts 8 Credits 16
The idea on the 13th floor is very inspiring. Why make it too complicated when it can be simple?
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023