Linked Questions

Popular Questions

Chunking misses out some files

Asked by At

I have 10000 files which I'm trying to split into 7 chunks and create simlinks to in a different place. For some reason, the last chunk ends up with exactly the same number of files as the other chunks, even though 10000 doesn't divide by 7 so it should have four extra. Why is this happening and how can I fix it?

import os

StartDir = "OriginalDir"
FirstEndDir   = "FirstSeventh"
SecondEndDir  = "SecondSeventh"
ThirdEndDir   = "ThirdSeventh"
FourthEndDir  = "FourthSeventh"
FifthEndDir   = "FifthSeventh"
SixthEndDir   = "SixthSeventh"
SeventhEndDir = "SeventhSeventh"

AllFileList = os.listdir(StartDir)

SortedList = sorted(AllFileList, key=lambda x: int(x.split("_")[-1].split(".")[0]))
print SortedList[0]

n = len(SortedList)/7

FirstList = [SortedList[i:i + n] for i in xrange(0, n, 1)]
SecondList = [SortedList[i:i + n] for i in xrange(n, 2*n, 1)]
ThirdList = [SortedList[i:i + n] for i in xrange(2*n, 3*n, 1)]
FourthList = [SortedList[i:i + n] for i in xrange(3*n, 4*n, 1)]
FifthList = [SortedList[i:i + n] for i in xrange(4*n, 5*n, 1)]
SixthList = [SortedList[i:i + n] for i in xrange(5*n, 6*n, 1)]
SeventhList = [SortedList[i:i + n] for i in xrange(6*n, len(SortedList), 1)]

for ii in FirstList[0]:
    print ii

for ii in SecondList[0]:
    print ii

for ii in ThirdList[0]:
    print ii

for ii in FourthList[0]:
    print ii

for ii in FifthList[0]:
    print ii

for ii in SixthList[0]:
    print ii

for ii in SeventhList[0]:
    print ii

Related Questions