A tool for automatically moving all mods from subfolders to "mods" folder.

Started by Tashei, January 10, 2024, 12:35:01 PM

Previous topic - Next topic

Tashei

Hello,
  here is a simple piece of code to save up to an hour of your time
After coming back to playing rimworld after some time, you might want to download a bunch of mods, libraries, addons and patches from various places.

  However, sometimes after unpacking all of them, you might notice that the game does not recognize any of them, and the reason is the folder strucure, which would look like this: C:\RimWorld.v1.4.3901\Mods\Mass Graves\Mass graves\all the modfiles such as Defs, abut etc\.

The folder "Mass Graves" is a subfolder of "Mass Graves", which is not only
unnecessary, but breaks the game.

Below is a piece of Python code. For it to work, simply edit the line 28 and paste your own location of "mods folder".

Everything has to be placed in Mods folder, it will not go through any other locations









import os
import shutil

def organize_mods_folder(mods_path):
    subfolders = [folder for folder in os.listdir(mods_path) if os.path.isdir(os.path.join(mods_path, folder))]

    for subfolder in subfolders:
        subfolder_path = os.path.join(mods_path, subfolder)
        subsubfolder_path = os.path.join(subfolder_path, subfolder)

        if os.path.exists(subsubfolder_path) and os.path.isdir(subsubfolder_path):
            for item in os.listdir(subsubfolder_path):
                item_path = os.path.join(subsubfolder_path, item)
                destination_path = os.path.join(subfolder_path, item)

                # Check if the destination path already exists
                if os.path.exists(destination_path):
                    print(f"Skipping {item} in {subfolder} - Destination path already exists.")
                else:
                    shutil.move(item_path, destination_path)

            # Remove the now-empty sub-subfolder and its contents
            shutil.rmtree(subsubfolder_path)

    print("Folder organization complete.")

# Specify the path to the "mods" folder
mods_folder_path = r"C:\Users\Central\Desktop\RimWorld.v1.4.3901\RimWorld.v1.4.3901\Mods"

# ^^^^^^^^^^^^^ CHANGE IT TO MATCH YOUR LOCATION OF THE MODS FOLDER ^^^^^^^^^^^^^^^^^^^^^^^^^

# Call the function to organize the mods folder
organize_mods_folder(mods_folder_path)