I'm trying to organize my ZX Spectrum game images on SD card for my Retroleum SMART Card adapter. Long file names are supported, and VFAT Long File Names (LFNs) cause too many clashes if I run through the list automatically. Is there a generally accepted set of heuristics for shortening file names to 8.3 with as few collisions as possible?

Some examples:

Long file name                                               8.3
Bomb Jack (1986)(Elite Systems).sna                       →  BOMBJACK.SNA
Cybernoid II - The Revenge (1988)(Hewson Consultants).sna →  CYBERND2.SNA
Football Manager 2 (1988)(Addictive Games).sna            →  FOOTMAN2.SNA
Manic Miner (1983)(Bug-Byte Software).sna                 →  MANICMIN.SNA
Pac-Mania (1988)(Grandslam Entertainments).sna            →  PACMANIA.SNA
Sentinel, The (1987)(Firebird Software).sna               →  SENTINEL.SNA
Spy vs Spy (1985)(Beyond Software).sna                    →  SPYVSSPY.SNA
Tapper (1985)(U.S. Gold).sna                              →  TAPPER.SNA
Technician Ted (1984)(Hewson Consultants).sna             →  TECHTED.SNA
Tetris (1988)(Mirrorsoft).sna                             →  TETRIS.SNA

I have access and knowledge of the typical Unix shell tools to rename the files.

  • There's always MS-style: XXXXXX~n – wizzwizz4 Jul 23 '16 at 15:50
  • Are tildes ('~') an acceptable character? – Mark Jul 23 '16 at 18:32
  • I'd prefer to avoid them. – scruss Jul 24 '16 at 2:06

You could use the Windows way: How Windows Generates 8.3 File Names from Long File Names. In short:

  1. Remove all invalid characters such as: " / \ [ ] : ; = ,
  2. Remove all periods, ., but the last one
  3. Truncate the file name (not including extension) to 6 characters
  4. Append a tilde, ~
  5. Append a 1. If the result corresponds to a file that already exists, change it to a 2. Or to a 3, etc.
  6. Truncate the extension to 3 characters
  7. Convert to uppercase

You can use this procedure or tweak it so that it is simpler. For example in step 1 you could just remove everything that is not a letter or a digit. Or you can ignore the "add tilde" step.

  • While this produces unique names, they're not very readable. I wanted to avoid the ~ approach, as it wastes ¼ of the available file name. – scruss Jul 24 '16 at 2:07
  • 1
    @scruss Then just skip the tilde altogether. But keep in mind that whatever you do, with a 8.3 schema you will never get very readable filenames. :-) – Konamiman Jul 24 '16 at 4:01
  • 1
    "Readable" and "automatic conversion" are pretty much mutually exclusive. – Mark Jul 24 '16 at 8:13
  • Note that Windows used the shortening algorithm even for shorter names, if the extension was longer than three characters. So for abc.docx, you might get abc~1.doc, for example. (Not sure if this was documented somewhere, but I distinctly recall noticing it back in the day...) – a CVn Jul 31 '16 at 14:39

You apparently have a fixed set of names that need unique 8.3 names - That is maybe a bit easier to solve than needing to have a unique hashing that will always end up with the same SFN from an LFN like Windows does. And you can get away without the tilde char that doesn't carry any useful information anyhow.

You might need to use a short program though, as I can't seem to be doing this in a shell language easily. See a bit of pseudocode how I would try and tackle the problem:

for all names do
  remove articles ("the", "a")
  replace roman numbers with arabic numbers (optional step)
  pick first 8 non-space letter chars (removes ".-+"...)
  check uniqueness of names, if a duplicate
     replace last characters with a running duplicate number

This is not optimal, as it doesn't try and abbreviate word parts - In case you have a dictionary of abbreviations (maybe the internet has one), you could even use that as a step 3

If your program would then offer you the short name, and long name with an option to edit the SFN, you could even fix non-optimal names manually as you go.

And it is always good practice to store the resulting translation table as a .txt file on the same medium that shows both long and short names for reference.

Your Answer

