Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Sort files in dir by date and time in its names

$
0
0
Hello scripters! I need to write a simple app which sort files in a directory by its names and keep only last 50. Auto delete the oldest files when more than 50 copies. Here are some filenames:
...
works12-30-12_10-55-30.tar.gz
sales12-21-12_14-03-49.tar.gz
names12-30-12_05-45-00.tar.gz
homes12-31-12_14-59-50.tar.gz
data01-01-13_21-05-30.tar.gz
cust01-01-13_21-55-18.tar.gz
...

and here are my function for split names:


[ autoit ]      
Func SplitNames($s) $sStrip = StringRegExpReplace($s,"[a-zA-Z.]","") ;remove all letters and "." Local $x = StringSplit($sStrip, "_") ;split date and time from "_" Global $fDate = StringRegExpReplace($x[1], '(\d{2})-(\d{2})-(\d{2})', '$2.$1.$3') ;transfer MM-DD-YY to DD.MM.YYYY Global $fTime = StringRegExpReplace($x[2], '-', ':') ;transfer 00-00-00 to 00:00:00 EndFunc SplitNames("data12-30-11_10-50-30.tar.gz") ConsoleWrite($fDate & @CR) ;Result: 30.12.11 ConsoleWrite($fTime & @CR) ;Result: 10:50:30

I need sort the names like this (desync date+time) and keep only 50 (newest) of it, others delete:

cust01-01-13_21-55-18.tar.gz
data01-01-13_21-05-30.tar.gz
homes12-31-12_14-59-50.tar.gz
works12-30-12_10-55-30.tar.gz
names12-30-12_05-45-00.tar.gz
sales12-21-12_14-03-49.tar.gz
...

Please help me and thanks for any ideas or snippets!

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>