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-08-02 20:32
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Extract and delete the specified date-named files from the text View 1,745 Replies 6
Original Poster Posted 2006-12-15 00:53 ·  中国 重庆 沙坪坝区 电信
初级用户
★★
Credits 105
Posts 77
Joined 2006-11-09 02:14
19-year member
UID 70077
Gender Male
From 重庆
Status Offline
There is a document a.txt with content and format as follows:
This is actually a list, with dates at the front and file names at the back
....
2005-12-02 43324
2005-12-03 232323
2005-12-04 rjjjdj
2005-12-05 fhsh
2005-12-06 sdhsh
....
2005-12-12
2005-12-13 fhhshs
2005-12-14
2005-12-15 fdhfg
....
Purpose: Use batch processing to extract the file names in a.txt and delete the files created within a specified period of time. I want to delete the files created from December 3, 2006 to December 15, 2006. Is there a good method?
Floor 2 Posted 2006-12-15 01:54 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The following is the demonstration code. Replace the echo statement with the del statement when you are satisfied:

@echo off
for /f "tokens=1*" %%i in (a.txt) do (
if %%i geq 2005-12-03 if %%i leq 2005-12-15 if not "%%j"=="" echo "%%j"
)
pause
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
redtek +5 2006-12-16 11:00
gene771771 +1 2006-12-17 00:33
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 3 Posted 2006-12-15 02:34 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Another alternative method to delete files between December 3, 2006 and December 15, 2006: )

(Note: The following command deletes files from December 3, 2006 to December 15, 2006 inclusive



rar a /R /M0 /DF /TA20061203 /TB20061216 compressed_file_name the directory where the batch of files with the specified date is located
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 4 Posted 2006-12-15 02:34 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Using the characteristics of the WinRAR compression tool, after execution, the deleted file is equivalent to being moved into the compressed package. If you don't want it anymore, just delete the compressed package.RAR. If you mistakenly delete it, you can also extract and recover it.

The above instruction has been tested and passed. The following gives the parameter explanation of WinRAR. RAR.EXE /? has more detailed help: )

(Note: I directly copied the rar.exe in the WinRAR compression tool directory to the windows directory for convenient calling, and I'm too lazy to modify the environment PATH information: )


ta<date> Process files modified after the <date> described in YYYYMMDDHHMMSS format

tb<date> Process files modified before the <date> described in YYYYMMDDHHMMSS format
       (Note: Refers to files before this date, not including the specified date of the day, so the date should be added by 1)


m<0..5> Set compression level (0-storage...3-default...5-max)
       (Note: Use /M0 parameter, because the compression process is the deletion process, /M0 is no compression but only storage, so the speed is fast)

df Delete files after generating the compressed archive
     (Note: That is, after compression, the source file is directly deleted, which plays the role of indirectly deleting unnecessary files in the directory)


r Include all subdirectories
     (Note: The /R parameter is to compress the files in all directories under the specified directory)

……

Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
lxmxn +5 2006-12-15 04:31
gene771771 +1 2006-12-17 00:35
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 5 Posted 2006-12-15 03:03 ·  中国 湖北 武汉 电信
初级用户
Credits 24
Posts 11
Joined 2006-09-30 09:07
19-year member
UID 64133
Status Offline
Learned, so it can be like this. Thanks for sharing
Floor 6 Posted 2006-12-15 04:32 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  It seems that Brother Redtek has a lot of research on various command-line tools, I've learned a lot. Plus points~
Floor 7 Posted 2006-12-16 10:03 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Well, it can also be achieved with winrar~ Learned it
Forum Jump: