China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-22 17:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Select and delete time-named files and classify them View 2,669 Replies 41
Floor 31 Posted 2008-05-26 15:26 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Silver member 【26933062】, if you see this, please help improve it!!! Thanks

When testing that day, a case was missed, that is, now it is June, so we should delete the files and folders before 200801!

But the current situation is that the things before 200701 are deleted! This is incorrect

It seems to be the reason for this section of the command, help analyze it (it seems that the date conversion was also done for the situation like if %mm% gtr 0)

if %mm% leq 0 set /a nn=1
set /a m=(12+mm)%%12,y=yy-nn
if %m% equ 0 set m=12
set m=0%m%
set yy=%y%%m:~-2%




Dear experts, please help, thanks
Floor 32 Posted 2008-05-26 15:32 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Originally posted by 26933062 at 2008-5-23 04:10 PM:
The experience is: a large number of practices, and read more others' posts
To run a bat in other positions, more issues need to be considered. The following code is not tested...
:

@echo off&setlocal enabledelayedexpansi ...

This is the final P
Floor 33 Posted 2008-05-26 15:39 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Hehe, I figured it out by myself. Just add one more case before if %mm% leq 0 set /a nn=1. Add: if %mm% gtr 0 set /a nn=0
Floor 34 Posted 2008-05-26 15:42 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Originally posted by easonL at 2008-5-26 15:39:
Hehe, I figured it out myself.
Just add another case before if %mm% leq 0 set /a nn=1.

Add:
if %mm% gtr 0 set /a nn=0

That's incorrect.
Modify here:
for /f "tokens=1,2 delims=:-\/. " %%a in ("%date%") do (
set /a yy=%%a,mm=100%%b%%100-5
)
致精致简!
Floor 35 Posted 2008-05-26 15:58 ·  中国 江苏 南京 电信
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Originally posted by 26933062 at 2008-5-26 03:42 PM:

That's not right,
Modify here
for /f "tokens=1,2 delims=:-\/. " %%a in ("%date%") do (
set /a yy=%%a,mm=100%%b%%100-5
)



Ah? You don't seem to have changed anything. Comparing with the original, I can't see it, heh heh
Floor 36 Posted 2008-05-26 16:16 ·  中国 江苏 南京 电信
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Silver member 【26933062】Big shot, and by the way, why is my modification like that incorrect? Please give a little analysis, please!
無求一生光輝 唯朢鬥志不會斷
Floor 37 Posted 2008-05-26 16:20 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
It seems there is indeed an error in the calculation part. Let me think about it.
致精致简!
Floor 38 Posted 2008-05-26 16:25 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
That's right! What problem are you having now?
致精致简!
Floor 39 Posted 2008-05-26 16:30 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
There is a mistake! Let me describe the problem:

If it's June now, then we should delete the files and folders before 200801, right?

But it's not like that now. The result is that only the files and folders before 200701 are deleted.

There seems to be a problem with the time calculation! You can take a look
無求一生光輝 唯朢鬥志不會斷
Floor 40 Posted 2008-05-26 16:33 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Wait a minute, I'll double - check it carefully!
無求一生光輝 唯朢鬥志不會斷
Floor 41 Posted 2008-05-26 16:35 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
How is that possible?
You test the following code...
:

@echo off
::The following is assuming the current date is June 2008, you can modify it yourself for testing
set date=2008/6
::::::::::::::::::::::::::::::
for /f "tokens=1,2 delims=:-\/. " %%a in ("%date%") do (
set /a yy=%%a,mm=100%%b%%100-5
)
if %mm% leq 0 set /a nn=1
set /a m=(12+mm)%%12,y=yy-nn
if %m% equ 0 set m=12
set m=0%m%
set yy=%y%%m:~-2%
echo.&echo Delete files before %yy% (including %yy%)
echo.&pause
致精致简!
Floor 42 Posted 2008-05-26 16:38 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Swe sweat~~~~~~~~~~
Why is the test result different from just now! It should be no problem!
I'm really sorry! I wasted your time

But it's really strange ah, I'll take a look at what happened just now by myself
無求一生光輝 唯朢鬥志不會斷
Forum Jump: