# Equally distribute thousands of items into 200 folders based on mathematical formula

I need to place around 80,000 images that will need to be stored on a single harddrive.

I would like to distribute them among 200 sub-directories.

The filename of each image will contain a 13-digit number.

Is there a way to distribute these in a someone equalized way between 200 sub-directories based on the number in the name.

Here are some sample file names:

9780306811548.jpg
9780306811562.jpg
9780306811579.jpg
9780306811586.jpg
9780306811593.jpg
9780306811609.jpg
9780306811616.jpg
9780306811623.jpg
9780306811630.jpg
9780306811654.jpg
9780306811661.jpg
9780306811692.jpg
9780306811715.jpg
9780306811722.jpg
9780306811739.jpg
9780306811746.jpg
9780306811753.jpg
9780306811760.jpg
9780306811777.jpg
9780306811784.jpg
9780306811807.jpg
9780306811821.jpg
9780306811838.jpg
9780306811852.jpg
9780306811869.jpg
9780306811876.jpg
9780306811913.jpg
9780306811937.jpg
9780306811944.jpg

My first idea was to place images in a folder with a name based on all the digits added together.

For example, 9780306807756.jpg would be placed in a sub-directory named "66" because
9 + 7 + 8 + 0 + 3 + 0 + 6 + 8 + 0 + 7 + 7 + 5 + 6 = 66

The problem is that this does NOT equally distribute the files among 200 directories.

LVL 16
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I don't know how your numbers are distributed, but how well equalized are they if you just take the number modulo 200?
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
place the images in numerical order
divide the number of images by the number of subfolders. That number will be N
Place the first N images in the first subfolder.
Continue until all images have been placed.
0
StatisticianCommented:
Hi there hankknight,

Your example numbers strictly increase by about 14, though the increment varies quite a bit.

The solution by ozo will distribute the pictures over the 200 folders, with adjacent pictures (in the incoming list) placed into folders approximately 14 apart.  If instead, you knocked off the last digit and then took that number modul0 200, adjacent pictures would often be either in the same folder (low frequency), in the next folder (mostly) or one or two folders removed (again low frequency).  That all assumes the pattern you have given is likely to continue.

The solution by aburr is good, provided you have all the pictures now and dont want a way of dealing with additional pictures in the future. It will put adjacent pictures in your list into the same folder, or (rarely, on a change of folder)  into the next folder.

Questions - Is it important to be able to know what folder a picture is in given its file name?  If so ozo solution (or my modification) is a good way to go.

Question - is it useful to have adjacent pictures in your list in the same or (rarely) the adjacent folder? If so the aburr solution is suitable.

Question - are new pictures going to keep coming after the first allocation?

Ian
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Math / Science

From novice to tech pro — start learning today.