Using captures

Converting logfile dates

Say you have a webserver that produces access logs of all the hits on your site, with every day being a new file in the format: accesslog.ddmmyyyy.txt. Over time you have accumulated a large number of these files:

Unfortunatly Windows Explorer decides to sort these files alphanumerically, which makes them difficult to nagivate in date order:

Using captures we can easily rename these files to a year-month-day format, which will be sorted correctly.


Step 1: In RegexRenamer, browse to the folder containing the files.

CLICK TO ENLARGE

Step 2: Type the following regex in the Match field: (\d\d)(\d\d)(\d\d\d\d) (match and capture two digits (day), two digits (month), and four digits (year)).

CLICK TO ENLARGE

Step 3: Type the following replace pattern in the Replace field: $3-$2-$1 (replace the numbers matched above with the contents of capture #3 (year), followed by a dash, followed by capture #2 (month), dash, and capture #1 (day)).

CLICK TO ENLARGE

Step 4: Click the Rename button to apply the changes.

CLICK TO ENLARGE

Now when you view the files in Windows Explorer they are sorted correctly: