5

I’m looking for a simple tool for Windows, GUI or CLI, doesn’t matter.
It should do the following:

Take a directory and a number as input and randomly move the files in that directory to subdirectories, each containing files up to the provided number.
So, random grouping essentially.

I’ll write it myself if it doesn’t exist, but let’s see if I can save me some work πŸ˜†

Comments
  • 1
    Maybe DropIt app can do that.

    http://www.dropitproject.com/

    I used it a lot when the amount of files I got was to high. I used it mainly to sort files in correct folders.
  • 1
    Just curious what you're doing it for? Ml?
  • 1
    @ScriptCoded no, just personal media preference
  • 1
    Do the subdirectory names have to mean anything or could they be a uuid?

    Also, how do you expect to find anything with such a folder structure?
  • 3
    @Lensflare Do you organize your media by random? πŸ€”
  • 1
    @ScriptCoded yes, I love randomizers
  • 2
    @cuddlyogre could be anything. I don’t want to find anything in particular. I want to be surprised.
  • 0
    @Grumm thanks, I’ll check it out
  • 2
    @Lensflare I guess that's one way to add spice to your daily routine.
  • 1
    That might be a nice task for chatgpt, maybe. I’ll try that.
  • 0
    Do you want it to recurse through the directory or just handle the files in the root?
  • 0
    If there are filename collisions, how should that be handled?
  • 0
    @cuddlyogre just root. Collisions can not happen because all the files are originally in one directory.
  • 2
    After many failed attempts, I could make chatgpt write a working script for me πŸ˜†

    It struggled a lot with the concept of random subfolder names, so I ended up omitting the random name requirement. It made consecutive numbers then. Good enough for me.

    It also had problems deciding what should be the number of subfolders until I explicitly told it how to calculate it.

    Still fascinating but not even close to "it will take our jobs" πŸ˜„
  • 1
    @Lensflare Oooh now I get it. "media" ;)
  • 2
    https://gist.github.com/cuddlyogre/...

    Here's a quick and dirty script that does what you're asking. It copies instead of moves, mostly because I didn't want to wreck my own folder structure, but everything else works the way you asked.

    I would have had it to you sooner, but I get to be the IT department today.

    Use at your own risk. I am not responsible for the results. bla bla bla
  • 1
    @cuddlyogre thanks but you didn’t have to. As I said, I already have one and it was a nice chatgpt learning experience πŸ˜„
  • 1
    @Lensflare It was a fun palette cleanser.
  • 4
    Here is the ChatGPT solution for anyone who is curious :)

    https://gist.github.com/WilhelmOks/...

    It took me about an hour to make ChatGPT write a working solution.
    It would probably be faster to write it myself but, I also wanted to test ChatGPT.
  • 0
    @Lensflare

    Yer gist ain't public.
  • 0
    @CoreFusionX yes but as long as you have the link, you should be able to see it. That’s what it said when I created it.
  • 1
    Something weird happened to that link. It worked before.
    Here it is again:

    https://gist.github.com/WilhelmOks/...
  • 0
    Described it to chatgpt and got this 2nd try. The first time was pretty good but it used a wildcard that didn’t account for the newly created folders.

    #!/bin/bash

    # Check if both parameters are provided
    if [ $# -ne 2 ]; then
    echo "Usage: $0 <folder path> <number of folders>"
    exit 1
    fi

    # Assign parameters to variables
    folder_path=$1
    num_folders=$2

    # Create folders
    for i in $(seq 1 $num_folders); do
    mkdir "${folder_path}/folder${i}"
    done

    # Move files randomly to new folders
    files=$(find "${folder_path}" -maxdepth 1 -type f) # Get all files in folder path
    num_files=$(echo "${files}" | wc -l) # Get number of files

    for ((i=1; i<=$num_files; i++)); do
    random_folder=$((RANDOM % num_folders + 1)) # Generate random folder number
    mv "$(echo "${files}" | sed "${i}q;d")" "${folder_path}/folder${random_folder}/" # Move file to random folder
    done

    echo "Done!"
  • 1
    Oh crap, the link might have been corrupted because I edited the comment. I need to check that in JoyRant.
Add Comment