A neat approach for sortable versioned filenames

A neat approach for sortable versioned filenames
tl;dr

Add a letter to indicate number of digits: a0, a1 to a9, b10 to b99, c100 to c999, etc.

Important disclaimer: I didn't come up with this scheme. I read it in a twitter X thread some time ago and have been using it ever since. I'm sure I bookmarked it, but I lost access to my account1

So, basically, I know you hate when you're dealing with files and start with

important_work.xlsx

and then realize that you better version this thing, so you F12 it and add a suffix indicating the version:

important_work.xlsx
important_work_v2.xlsx

That works, so back again to doing your job. Then, after a few back and forth with peers/boss/clients you find yourself with over 10 versions:

important_work.xlsx
important_work_v10.xlsx
important_work_v2.xlsx
important_work_v3.xlsx
important_work_v4.xlsx
important_work_v5.xlsx
important_work_v6.xlsx
important_work_v7.xlsx
important_work_v8.xlsx
important_work_v9.xlsx

Wait a sec, what is that? let's zoom in

important_work.xlsx
important_work_v10.xlsx
important_work_v2.xlsx

This is awfully out of order! Totally unacceptable in a professional setting.

Luckily for you, you were born a very sharp file namer, so you always start your versions at _v01, right? Well, that works until the day your team does the 100th change to the spreadsheet or jupyter notebook that runs the whole org's backoffice, so now you're back at square 1 - or rather, square _v100.

There's a very elegant solution to this problem that I've been using for a few years now: just add a letter to the beginning of the version number that indicates how many digits it has: "a" for one digit, "b" for two, etc.:

important_work.xlsx
important_work_va2.xlsx
important_work_va3.xlsx
important_work_va4.xlsx
important_work_va5.xlsx
important_work_va6.xlsx
important_work_va7.xlsx
important_work_va8.xlsx
important_work_va9.xlsx
important_work_vb10.xlsx

This works beautifully2 with semver!

a1.a3.a3
a1.b10.a2

I also wrote (to be honest, Claude did) a small, non-pip installable python module to those too busy to count number of digits in an integer: lexisortable. The module has an official upper limit of one mole, 2019 revision. There's no technical reason for that, but if you're going over that limit you should probably look into git.

  1. if anyone from X is reading this, please know the sms recovery code for forgotten passwords is apparently not working in Brazil. I know it's not your favorite market and that I should have registered using an email, but alas. ↩︎
  2. I kid, I know that's ugly. But it is sortable!↩︎

Comments

Popular posts from this blog

JIT and GIL removal are not even my most anticipated Python 3.13 features

An interview with Steve Wozniak by Jessica Livingston cured my AI anxiety

What if regular exercise is the best cognitive exercise?