post image 2 min read

Renaming files using Power Toys and ChatGPT

I had about 30 files in a Windows folder that roughly followed a naming convention that had a date or year at the end of the file name. For example “Interesting Report 2021.pdf” or “Invoice 2024-01-12.xlsx”. It also included other files that didn’t include any dates, such as “Certificate.docx”.

I decided that I wanted to rename these files to include the date at the beginning of the file name, so that they would sort in date order. For example “2021 Interesting Report.pdf” or “2024-01-12 Invoice.xlsx”. But who wants to rename 30 files manually? Not me!

Microsoft have a great free tools collection called Power Toys. This includes Power Rename, which allows you to rename files in bulk. It has an advanced feature that lets you use regular expressions to match and replace text. Great! But I’m not a regular expression expert. No problem, I entered the following prompt into ChatGPT:

I need a regular expression to check a file name. If the last word of the file name is a number or a date, move it to the start of the filename

This is the regular expression it generated for me:

^(.*?)(\d{4}-\d{2}-\d{2}|\d+)(\.[^.]+)$

It also generated JavaScript to perform the rename using this expression. However, I needed a format that Power Rename could use. I clicked the help link in Power Rename and figured out the format I needed was

$2 $1$3

Power Rename shows you a preview of the before and after file names, so I was able to confirm that this was what I wanted. Click the Apply button and voila! A tedious, error-prone job finished in a few seconds. OneDrive sync pushed these changes to SharePoint and I was done.

While this is great, what I really would love is support for metadata in File Explorer. Old habits die hard and I still like to use File Explorer to navigate my files. I know that I need to develop a new habit of using SharePoint to navigate my files, but I’m not there yet.

In the mean time, I like that I can combine the power of Power Toys and ChatGPT to get things done.