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 16:16
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Select and delete time-named files and classify them View 2,665 Replies 41
Floor 16 Posted 2008-05-23 14:59 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
If you put the bat file in the D:\tabiplaza\yado\debug folder and run it, then the directory path of my abcd folder doesn't matter.

Are there any other files in your D:\tabiplaza\yado\debug folder besides the log file you mentioned?

What other folders are there in the D:\tabiplaza\yado\debug folder?

Or run the following code and post the result of a.txt:
@echo off
for /f "delims=" %%a in ('dir/b/ad') do echo %%a>>a.txt
pause
致精致简!
Floor 17 Posted 2008-05-23 15:13 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Now the situation here is as follows:

The log files and bat files are placed under D:\tabiplaza\yado\debug

I did not create the abcd folder

The result of running is: A folder named with the year and month is generated under D:\tabiplaza\yado\debug, and the log files are placed in the folder. This process does not delete files (including outdated files and folders)

In addition, I saw the code " 'dir/b/ad' " ,does this sentence have anything to do with it?
Floor 18 Posted 2008-05-23 15:22 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
for /f "delims=" %%a in ('dir/b/ad') do if %%a leq %yy% rd/q/s "%%a"
This line is to judge that if the folders in the D:\tabiplaza\yado\debug folder are less than 6 months old, they will be deleted (the folder names are all in the form of year and month).
You said that there are folders named with year and month generated under D:\tabiplaza\yado\debug. Are there any folders before 200801 among these folders?
After running the bat file, there should be no log files in the D:\tabiplaza\yado\debug folder, because the files less than 200801 have been deleted, and the files greater than or equal to 200801 have been moved to the corresponding folders.
Isn't that the case?
致精致简!
Floor 19 Posted 2008-05-23 15:26 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
1. In the D:\tabiplaza\yado\debug folder, besides the log files, there are no other files (of course, there are also bat files).
2. After running once via the bat, the folders under D:\tabiplaza\yado\debug are:
200703
200709
200801
200802
200803
200808
Floor 20 Posted 2008-05-23 15:29 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
How could this be?
Run the following code and paste the result...
:

@echo off&setlocal enabledelayedexpansion
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 "%yy%"
pause
致精致简!
Floor 21 Posted 2008-05-23 15:30 ·  中国 江苏 南京 联通
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
I'm sorry, I didn't see your reply just now, so I replied with the above content.

After running the bat file, there should be no log file in the D:\tabiplaza\yado\debug folder. It has been moved to the corresponding folder, but the folder smaller than 200801 still exists!!

I suddenly remembered a situation and want to tell you. My system is an English system. Will this affect it?
I'm afraid there is a difference in the system time format, which will affect the result?
Floor 22 Posted 2008-05-23 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 03:29 PM:
How could this be?
Run the following code and post the result...
:

@echo off&setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=:-\. " %%a in ("%date ...


Running result:
D:\tabiplaza\yado\debug>test2
"1607"
Press any key to continue . . .
Floor 23 Posted 2008-05-23 15:33 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Ah???
Is there any mistake?
It is indeed caused by the time format.
What is the result when you run
echo %date% again?

[ Last edited by 26933062 on 2008-5-23 at 03:35 PM ]
致精致简!
Floor 24 Posted 2008-05-23 15:35 ·  中国 江苏 南京 电信
初级用户
★★
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 03:33 PM:
Ah???
Is there any mistake?
Run again
echo %date%
What is the result?



Result of echo:
2008/05/23
Floor 25 Posted 2008-05-23 15:37 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
for /f "tokens=1,2 delims=:-/. " %%a in ("%date%") do (
Just change this sentence to
for /f "tokens=1,2 delims=:-/. " %%a in ("%date%") do (
and it will be okay
Or copy the code from building 4 and run it again
致精致简!
Floor 26 Posted 2008-05-23 15:40 ·  中国 江苏 南京 电信
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Wow!!!!!
It's so powerful, it's really fixed!!
Hehe, what's the reason? Can you analyze it?
Floor 27 Posted 2008-05-23 15:51 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
delims=:-\. I used these 4 symbols :-\. before to ensure no mistakes to split %date% to get year, month and day, but I didn't expect your date separator is /
Alas!... A slip betrays a thousand worries...
Actually, just using delims=/ is okay.

[ Last edited by 26933062 on 2008-5-23 at 03:52 PM ]
致精致简!
Floor 28 Posted 2008-05-23 16:00 ·  中国 江苏 南京 电信
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
First of all, express gratitude!! Thank you very much for your help!

Hehe, originally writing code just needs a lot of debugging, which is purely normal! It's just that this error is magnified when not debugging in one's own environment!

I don't understand the operating mechanism of P, and I still trouble you to continue answering questions!
1. Now we put the bat in D:\tabiplaza\yado\debug. If I add D:\tabiplaza\yado\debug to the environment variables, will it be possible to run the bat file anywhere? But the problem now is that if I want to change the path of the bat file, for example, I want to put it under C:\, and the D:\tabiplaza\yado\debug is still for placing log files, how to change it?
2. In the preparatory entry stage of learning P, according to my own learning experience, in addition to a lot of practice, do you have any particularly scientific experiences, can you give some advice, thank you
Floor 29 Posted 2008-05-23 16:10 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Experience is: a lot of practice, and read more people's posts.

To run a bat in other positions, you need to consider more issues. The following code has not been tested...

:

@echo off&setlocal enabledelayedexpansion
set "lj=D:\tabiplaza\yado\debug"
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%
for /f "delims=" %%a in ('dir/b/ad "%lj%"') do if %%a leq %yy% rd/q/s "%lj%\%%~nxa"
for /f "delims=" %%a in ('dir/b/a-d "%lj%\*.log"') do (
set "str=%%~nxa"
set "str=!str:~0,6!"
if !str! leq %yy% (del/q "%lj%\%%~nxa") else (
if not exist "%lj%\!str!\" md "%lj%\!str!"
move "%lj%\%%~nxa" "%lj%\!str!"
)
)
pause
致精致简!
Floor 30 Posted 2008-05-23 16:13 ·  中国 江苏 南京 电信
初级用户
★★
E生迅徒
Credits 118
Posts 56
Joined 2008-05-22 16:34
18-year member
UID 119421
Gender Male
From 南京
Status Offline
Well, thank you, and I'll continue to study! I'll come to you for help if I encounter problems!
I'm very grateful!
Forum Jump: