RetroDECK icon indicating copy to clipboard operation
RetroDECK copied to clipboard

Tool: Folder as a file function, m3u creator

Open XargonWan opened this issue 3 years ago • 3 comments

Evaluate the creation of a new function: "Folder as a file creator". The user inputs a folder, and creates the "folder as a file structure", so basically:

  • read the filenames contained in a folder
  • (?) Let the user choose the file order
  • creates a .m3u with all the filenames ordered by name
  • renames the folder accordingly

NOTE: it requires unix line endings in the file (encoding to UTF-8)

XargonWan avatar Mar 26 '23 11:03 XargonWan

Proto script that I did, it worked very well with my collection:

#!/bin/bash

# Function to create multidisk directories
create_multidisk_directories() {
    echo "Checking for games with multiple .chd files..."
    # Loop through each file in the current directory
    for file in *; do
        # Convert the file name to lowercase for matching
        lower_file=$(echo "$file" | tr '[:upper:]' '[:lower:]')
        # Check if the lowercase file name contains disc/disk/cd followed by a space or a number
        if [[ "$lower_file" =~ (disc|disk|cd)[[:space:]]?[0-9]* ]]; then
            echo "Found game with possible multidisk: $file"
            # Get base name without (Disc X) part
            base_name=$(echo "$file" | sed -E 's/ \((Disc|Disk|CD)[[:space:]]?[0-9]+\)\.chd//I')
            # Create a directory for the game
            mkdir -p "$base_name.m3u"
            # Move the files into the game directory
            mv "$file" "$base_name.m3u/"
            mv "${base_name}*(Disc|Disk|CD)[[:space:]]?[0-9]*.chd" "$base_name.m3u/"
            # Change directory to the game directory
            cd "$base_name.m3u" || exit
            # Create the .m3u file
            touch "${base_name}.m3u"
            # Write unique .chd file names to .m3u file (case-insensitive)
            for chd_file in *.chd; do
                if ! grep -iq "$chd_file" "${base_name}.m3u"; then
                    echo "$chd_file" >> "${base_name}.m3u"
                fi
            done
            echo "Multidisk directory created for: $base_name"
            # Move back to original directory
            cd ..
        else
            echo "Skipping $file, does not match the criteria for Disc/Disk/CD."
        fi
    done
    echo "Multidisk directories creation complete."
}

# Call function to create multidisk directories
create_multidisk_directories

XargonWan avatar May 08 '24 12:05 XargonWan

I will wait for Godot Configurator prior to integrate this

XargonWan avatar Aug 22 '24 12:08 XargonWan