|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『楼 主』:
[求助]对以时间命名的文件进行选择删除和分类
使用 LLM 解释/回答一下
现在需要对log文件进行处理,文件名的命名规则如下:
.log
例)
D:\tabiplaza\yado\debug\20080522000200.log
批处理要求:
1、六个月前的文件,删除
2、五个月前的文件,进行分类,每个文件按照月份放入对应的文件夹(以月份命名)。
例如:D:\tabiplaza\yado\debug\20080522000200.log->文件夹:200805
由于初次接触批处理,基本上属于准备入门状态,请求版主以及各位大虾帮忙出出注意!不胜感激!
(另外,搜索没找到什么结果,也有可能搜索的关键字不对,希望指教!)
Last edited by easonL on 2008-5-26 at 03:19 PM ]
Now we need to process log files. The naming rule of the file name is as follows:
.log
Example)
D:\tabiplaza\yado\debug\20080522000200.log
Batch processing requirements:
1. Delete files that are six months ago.
2. Classify files that are five months ago. Put each file into the corresponding folder according to the month, and name the folder with the month.
For example: D:\tabiplaza\yado\debug\20080522000200.log -> folder: 200805
Since I am initially exposed to batch processing and basically at the entry-level state, I ask the moderator and all the experts to help come up with ideas! Thank you very much!
(In addition, I didn't find any results when searching, and it may also be that the search keywords are incorrect. I hope to get some guidance!)
Last edited by easonL on 2008-5-26 at 03:19 PM ]
|
|
2008-5-23 10:49 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
假设现在已经对5个月前的log分类了,下个月处理的时候是否需要在判断分类文件夹里面的文件是否超过6个月呢?
Assuming that the logs from 5 months ago have been classified, do we need to check if the files in the judgment classification folder exceed 6 months when processing next month?
|

 |
|
2008-5-23 11:20 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
需要的,我的想法是:
下个月执行批处理的话,首先根据文件名来判断下,如果是六个月前的文件夹,就直接删除整个文件夹。
例如:现在2008年5月,那么200712这个文件夹我就直接删除好了
Needed, my idea is:
If we execute the batch processing next month, first, judge according to the file name. If it is a folder from six months ago, directly delete the entire folder.
For example: Now it is May 2008, then the folder 200712 I will directly delete it
|
|
2008-5-23 11:25 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
放在D:\tabiplaza\yado\debug文件夹运行,
未测试。。。
@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%
for /f "delims=" %%a in ('dir/b/ad') do if %%a leq %yy% rd/q/s "%%a"
for /f "delims=" %%a in ('dir/b/a-d *.log') do (
set "str=%%~nxa"
set "str=!str:~0,6!"
if !str! leq %yy% (del/q "%%a") else (
if not exist !str!\ md !str!
move "%%a" "!str!"
)
)
pause
Last edited by 26933062 on 2008-5-23 at 03:38 PM ]
Run in the D:\tabiplaza\yado\debug folder,
Not tested...
@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%
for /f "delims=" %%a in ('dir/b/ad') do if %%a leq %yy% rd/q/s "%%a"
for /f "delims=" %%a in ('dir/b/a-d *.log') do (
set "str=%%~nxa"
set "str=!str:~0,6!"
if !str! leq %yy% (del/q "%%a") else (
if not exist !str!\ md !str!
move "%%a" "!str!"
)
)
pause
Last edited by 26933062 on 2008-5-23 at 03:38 PM ]
|

致精致简! |
|
2008-5-23 13:34 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2008-5-23 01:34 PM:
放在D:\tabiplaza\yado\debug文件夹运行,
未测试。。。
:
@echo off&setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=:-\. " %%a in ("%date%") d ...
非常感谢,我正在测试,不过遇到一些问题,继续请教
1、我保存在D:\tabiplaza\yado\debug底下,命名未debug.bat
2、想让它输出点提示信息,可是cmd那个黑屏总是一闪就没有了,这是为什么?
呵呵,觉得自己真的很菜,不过没办法,学习总是这样一个过程,多多赐教,不胜感激!
Originally posted by 26933062 at 2008-5-23 01:34 PM:
Run it in the D:\tabiplaza\yado\debug folder,
Not tested...
:
@echo off&setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=:-\. " %%a in ("%date%") d ...
Thanks a lot. I'm testing it, but I encountered some problems. I'll continue to ask for advice.
1. I saved it in D:\tabiplaza\yado\debug and named it debug.bat.
2. I want it to output some prompt information, but the black screen of cmd always flashes and disappears. Why is that?
Hehe, I feel really stupid, but there's no way. Learning is always such a process. Please give me more advice. I'm very grateful!
|
|
2008-5-23 14:01 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
一闪就没有了,是代码有错误,不好意识,粗心大意将%yy%写成了%yy%%
现以改正,再试试。。
It flashed and then disappeared. There was an error in the code. Sorry, I carelessly wrote %yy% as %yy%%. Now it has been corrected, let's try again.
|

致精致简! |
|
2008-5-23 14:05 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
跑到for /f "delims=" %%a in ('dir/b/ad') do if %%a leq %yy%% rd/q/s "%%a"
这一句的时候出错:
The syntax of the command is incorrect.
原因正在调查中
When running to the line "for /f "delims=" %%a in ('dir/b/ad') do if %%a leq %yy%% rd/q/s "%%a"", an error occurs:
The syntax of the command is incorrect.
The reason is under investigation
|
|
2008-5-23 14:10 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
都说了这一句有错,你重新复制4楼代码再试试。。。。
I said it's wrong here, you re - copy the code from floor 4 and give it a try...
|

致精致简! |
|
2008-5-23 14:15 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
@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%
for /f "delims=" %%a in ('dir/b/ad') do if %%a leq %yy% rd/q/s "%%a"
for /f "delims=" %%a in ('dir/b/a-d *.log') do (
set "str=%%~nxa"
if !str:~0,6! leq %yy% (del/q "%%a") else (
if not exist !str:~0,6!\ md !str:~0,6!
move "%%a" "!str:~0,6!"
)
)
pause
----------------------------------------------------------------------------------------
将后面两个运算变量%yy%后,运行的错误是:
6! was unexpected at this time.
好像是最后那句if还有错,呵呵,费神再看看,谢谢
@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%
for /f "delims=" %%a in ('dir/b/ad') do if %%a leq %yy% rd/q/s "%%a"
for /f "delims=" %%a in ('dir/b/a-d *.log') do (
set "str=%%~nxa"
if !str:~0,6! leq %yy% (del/q "%%a") else (
if not exist !str:~0,6!\ md !str:~0,6!
move "%%a" "!str:~0,6!"
)
)
pause
----------------------------------------------------------------------------------------
The error when running after adding the two operation variables %yy% later is:
6! was unexpected at this time.
It seems there is still an error in the last if sentence. Hehe, take some time to look again, thank you
|
|
2008-5-23 14:17 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
汗!果然,
以修改并测试成功。。。
Sweat! Indeed,
It has been modified and tested successfully...
|

致精致简! |
|
2008-5-23 14:28 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
呵呵,是的!现在已经能够分类了,感谢!
老大,但是删除超过时间的文件的功能没有实现,呵呵
Hehe, yes! Now it can be classified, thanks!
Boss, but the function to delete files that have exceeded the time has not been implemented, hehe
|
|
2008-5-23 14:31 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
我测试可以啊!
if !str! leq %yy% (del/q "%%a")
这句就是删除文件的啊?
I can test it!
if !str! leq %yy% (del/q "%%a")
Is this sentence for deleting files?
|

致精致简! |
|
2008-5-23 14:34 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
啊?不是吧,我测试的时候,总是建立对应的文件夹,然后把文件放进去(包括六个月前的)。
我觉得可能是目录结构的差异?
我这边的目录结构是:
D:\tabiplaza\yado\debug\底下放文件夹、文件
是这样吗?
Ah? No way, when I tested, I always created the corresponding folder and put the files in it (including those from six months ago). I think it might be a difference in directory structure?
The directory structure here is:
Files and folders are placed under D:\tabiplaza\yado\debug\
Is that so?
|
|
2008-5-23 14:42 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
我在abcd文件夹里创建了以下这些log文件
然后运行4楼的代码。
abcd文件夹里只剩下200801-----2008-05文件夹,里面是相应的文件。
已经没有2007开头的文件了,难道不对?
:
200701dfjg.log
200702dfgs.log
200703fhhhgh.log
200710sfysh.log
200711sdfhsh.log
200712sfdhsh.log
200801sdfhsghgh.log
200802sdfhgsh.log
200805sfdhstsr.log
200803sfdhs.log
200804sghsgh.log
200701dfjgfg.log
200702dfgssdfg.log
200703fhhhghsdg.log
200710sfyshsfg.log
200711sdfhshsdfg.log
200712sfdhshsfg.log
200801sdfhsghghsfg.log
200802sdfhgshsdg80.log
200805sfdhstsrsdfg678.log
200803sfdhssgj68.log
200804sghsghh6.log
I created the following log files in the abcd folder.
Then I ran the code from floor 4.
In the abcd folder, only the 200801-----2008-05 folder remains, and the corresponding files are inside.
There are no longer any files starting with 2007. Is that incorrect?
:
200701dfjg.log
200702dfgs.log
200703fhhhgh.log
200710sfysh.log
200711sdfhsh.log
200712sfdhsh.log
200801sdfhsghgh.log
200802sdfhgsh.log
200805sfdhstsr.log
200803sfdhs.log
200804sghsgh.log
200701dfjgfg.log
200702dfgssdfg.log
200703fhhhghsdg.log
200710sfyshsfg.log
200711sdfhshsdfg.log
200712sfdhshsfg.log
200801sdfhsghghsfg.log
200802sdfhgshsdg80.log
200805sfdhstsrsdfg678.log
200803sfdhssgj68.log
200804sghsghh6.log
|

致精致简! |
|
2008-5-23 14:47 |
|
|
easonL
初级用户
  E生迅徒
积分 118
发帖 56
注册 2008-5-22 来自 南京
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
晕倒,果然是目录结构不一样,呵呵,怪我看代码,不能很好理解啊,菜鸟菜鸟啊
老大,两个问题:
1、D:\tabiplaza\yado\debug下面放的是bat文件,这个应该对的!
2、你的abcd文件夹的目录路径什么?
哎,要不是急着做出来,我一定等到能完全看懂代码的时候,再向你好好请教!
Fainted, it turns out the directory structure is different. Hehe, it's my fault for not being able to understand the code well. I'm a newbie, newbie.
Boss, two questions:
1. The bat files are placed in D:\tabiplaza\yado\debug, which should be correct!
2. What's the directory path of your abcd folder?
Hey, if I weren't in a hurry to get it done, I would definitely wait until I can fully understand the code before asking you carefully!
|
|
2008-5-23 14:54 |
|