Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Grumm18102yMaybe 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. -
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? -
@cuddlyogre could be anything. I don’t want to find anything in particular. I want to be surprised.
-
Do you want it to recurse through the directory or just handle the files in the root?
-
@cuddlyogre just root. Collisions can not happen because all the files are originally in one directory.
-
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" π -
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 -
@cuddlyogre thanks but you didn’t have to. As I said, I already have one and it was a nice chatgpt learning experience π
-
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. -
@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.
-
Something weird happened to that link. It worked before.
Here it is again:
https://gist.github.com/WilhelmOks/... -
tedge3072yDescribed 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!" -
Oh crap, the link might have been corrupted because I edited the comment. I need to check that in JoyRant.
Related Rants
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 π
question
random
grouping
files
windows