A Script to Organize ROMs by Filename

For topics which do not fit in other specific forums.
jamespo
Posts: 11
Joined: Sat Nov 19, 2022 1:37 pm
Has thanked: 2 times
Been thanked: 3 times

A Script to Organize ROMs by Filename

Unread post by jamespo »

If you have a large directory with 100s or 1000s of roms, this script will create subdirectories a b c d etc and move the files in there, based on the first letter of their filename: https://github.com/jamespo/directorysorter

Files beginning with numbers go into a 0-9 directory & everything else goes into an _others directory.

Written in Python 3, no warranty is given, use at your own risk! I'd suggest you try it in a test directory first.

User avatar
Chris23235
Top Contributor
Posts: 982
Joined: Sun May 24, 2020 8:45 pm
Has thanked: 127 times
Been thanked: 197 times

Re: A Script to Organize ROMs by Filename

Unread post by Chris23235 »

jamespo wrote: Tue Dec 20, 2022 7:46 pm

If you have a large directory with 100s or 1000s of roms, this script will create subdirectories a b c d etc and move the files in there, based on the first letter of their filename: https://github.com/jamespo/directorysorter

Files beginning with numbers go into a 0-9 directory & everything else goes into an _others directory.

Written in Python 3, no warranty is given, use at your own risk! I'd suggest you try it in a test directory first.

Thank you, such a script comes in handy. If you are on Windows, you can use this small batch I once wrote for this purpose:

Code: Select all

echo Create Folder
md a b c d e f g h i j k l m n o p q r s t u v w x y z #
echo Delete ZIP Files
del *.zip
echo Delete Bad Dumps
del *[b*.*
echo Move Files
move a*.* a
move b*.* b
move c*.* c
move d*.* d
move e*.* e
move f*.* f
move g*.* g
move h*.* h
move i*.* i
move j*.* j
move k*.* k
move l*.* l
move m*.* m
move n*.* n
move o*.* o
move p*.* p
move q*.* q
move r*.* r
move s*.* s
move t*.* t
move u*.* u
move v*.* v
move w*.* w
move x*.* x
move y*.* y
move z*.* z
move *.* #
pause

When run it will first delete all zip files and then all bad dumps. If you want to work with zipped files delete the line and the bad dumps are only deleted if the files have the GoodSet name convention. After running the file you have to manually delete the batch from the folder #.

Unlike the script from jamespo this will only work on Windows.

User avatar
pgimeno
Top Contributor
Posts: 709
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: A Script to Organize ROMs by Filename

Unread post by pgimeno »

Bash is great for these kind of things, and MiSTer has it of course. Here's a short script that does this:

Code: Select all

mkdir {A..Z}
for i in {A..Z} ; do
  mv "$i"?* "${i,}"?* "$i/"
done
mkdir -p 1
for i in ??* ; do
  mv "$i" 1/
done
rmdir 1 {A..Z}  # remove empty folders

It may spit a few errors that can be ignored. This one doesn't create 0, 1, ..., 9 folders or the "_others" folder, it would be easy to do but I personally prefer to have everything with numbers and symbols in the same folder, since there are usually very few of them to justify such segregation. So everything not alphabetic goes to the 1/ folder.

But for ROMs and tapes, I prefer to zip the stuff and have 1.zip, A.zip, B.zip, C.zip and so on. Sometimes for floppies too, but keep in mind that writes to floppies won't be stored. This script will do the trick:

Code: Select all

for i in {A..Z} ; do
  zip -9m "$i".zip "$i"* "${i,}"*
done
zip -9m 1.zip [!A-Za-z]*

As for how to use these, you can just copy them to a file in the MiSTer's Linux and then, from bash, run 'source <file>' on the folder with the ROMs. Or if you can copy/paste the commands directly to an SSH session, that works too.

Post Reply