In chatGPT, I asked:
I am trying to build a RetroPie system. I bought a MicroSD Card with RetroPie installed and it comes with 10,000 games. RetroPie organizes the games (aka roms) into subdirectories based on the platform the game runs on. Example platforms foor the brand Nintendo are Nintendo 64 (n64), Super Nintendo Entertainment System (snes) and Nintendo Entertainment System (RetroPie/roms/nes). There are over 20 platforms. My goal is to reduce the number of games available in RetroPie by moving them to an unused subdirectory, such as, RetroPie/roms/unused/nes. I would also like to minimize the number of duplicate games within a brand's platforms. Because of the large number of games, this is very manpower intensive. I have done four platforms manually using linux commands (mkdir RetroPie/roms/unused/nes, cd RetroPie/roms/nes, and then mv <game> ../unused/nes/..). I though it might be faster to run ls -1 and put this output in a spreadsheet, color code each platform's games, sort them, and then make one column to keep and one column to move. Can you thinkk about this approach and provide a more efficient one? If possible, can you also provide the linux scripts necessary to do this?
chatGPT responded:
You have a solid start, but there might be a more efficient approach to manage your RetroPie system. Here’s a streamlined method that combines shell scripting and a spreadsheet for a visual overview:
1, Generate a List of All Games:
You can use find to recursively list all game files by platform. For example, in a terminal window on the RetroPie run the command:
$ pwd
/home/pi
$ find RetroPie/roms -type d \( -name 'media' -o -name 'unused' -prune \) -o -type f > all_games.txt
Note: After asking chatGPT addditional questions, I made some minor clarifications and edits to the original output.
2. Import the List into a Spreadsheet:
To copy all_games.txt to the MacBook, open a terminal window and run the commands:
$ scp pi@retropie.local:/home/pi/all_games.txt ~/Desktop
Open all_games.txt in Excel Each line will contain the full path of a game. You can then color-code and sort them as needed.
3. Identify and Mark Duplicates:
Note: none of the duplicate games have an identical checksum.
You can use this command to identify duplicates on RetroPie:
$ find RetroPie/roms -type f ! -path "*/media/*" ! -path "*/unused/*" | sort | uniq -w32 -dD > duplicates.txt
This will create a list of duplicate games. Import duplicates.txt into the spreadsheet, and decide which copies to keep
need to scp duplicates to macbook
also describe steps to mark as move
=FIND(CHAR(134),SUBSTITUTE(C5,"/",CHAR(134),(LEN(C5)-LEN(SUBSTITUTE(C5,"/","")))/LEN("/")))
4. Generate a Move Script Based on Your Spreadsheet:
After marking the games to move in your spreadsheet, export the list of these games to a text file (let's call it move_list.txt).
Then, create a script to move them using an editor ($ nano move.sh):
#!/bin/bash
move_list="move_list.txt"
while IFS= read -r game; do
platform=$(echo "$game" | cut -d'/' -f3)
destination="RetroPie/roms/unused/$platform/"
mkdir -p "$destination"
mv "$game" "$destination"
done < "$move_list"
Then run it: $ move.sh