Renaming files based on file contents


#1

Hello,

I have a folder of over 6,000 Excel files that I need renamed (perfect for automation, huh?). All of these files currently have random names. For example, one of them is named “000e8d53-86e0-4fb3-a3e8-7453c95b2601.xlsx.” I need to somehow get these files renamed and restructured.

I’d like to be able to rename them based on content INSIDE the excel file. All of the files are the same format, and include data like a date, product number, and customer name. Is there a way to write a script (or maybe use Hazel) to look inside the excel documents, grab the data, and then rename the file?

Thanks in advance! (Oh, and I LOVE the podcast :slight_smile:)


#2

I know that you would be able to use Python (using openpyxl) or Perl (using Spreadsheet::Read) to do this. I don’t know the file format of Excel well enough, nor which languages you feel comfortable with, to be able to recommend a general solution.

I know you could also be able to do this with AppleScript, but my (ancient) experience tells me that might be a headache.


#3

Thanks @Iaaph

I ended up figuring it out! Thanks for pointing me to Openpyxl. Great resource!


#4

How did you do it in the end? What was your approach? I am eager to learn.
Right now the first thing which comes to my mind is to use Hazels match patterns… that should work.