Merge pull request #1 from dgnthr/master
Fixed errors due to integer division.
This commit is contained in:
commit
38b70c8f22
|
@ -10,18 +10,18 @@ def limitFilesPerFolder(folder, maxNumberOfFilesPerFolder):
|
||||||
dirPath = os.path.join(root, dir)
|
dirPath = os.path.join(root, dir)
|
||||||
filesInFolder = len(os.listdir(dirPath))
|
filesInFolder = len(os.listdir(dirPath))
|
||||||
if(filesInFolder > maxNumberOfFilesPerFolder):
|
if(filesInFolder > maxNumberOfFilesPerFolder):
|
||||||
numberOfSubfolders = math.ceil(filesInFolder / maxNumberOfFilesPerFolder)
|
numberOfSubfolders = ((filesInFolder - 1) // maxNumberOfFilesPerFolder) + 1
|
||||||
for subFolderNumber in range(1, numberOfSubfolders+1):
|
for subFolderNumber in range(1, numberOfSubfolders+1):
|
||||||
subFolderPath = os.path.join(dirPath, str(subFolderNumber))
|
subFolderPath = os.path.join(dirPath, str(subFolderNumber))
|
||||||
if not os.path.exists(subFolderPath):
|
if not os.path.exists(subFolderPath):
|
||||||
os.mkdir(subFolderPath)
|
os.mkdir(subFolderPath)
|
||||||
fileCounter = 0
|
fileCounter = 1
|
||||||
for file in os.listdir(dirPath):
|
for file in os.listdir(dirPath):
|
||||||
source = os.path.join(dirPath, file)
|
source = os.path.join(dirPath, file)
|
||||||
if os.path.isfile(source):
|
if os.path.isfile(source):
|
||||||
destDir = str(math.floor(fileCounter / maxNumberOfFilesPerFolder)+1)
|
destDir = str(((fileCounter - 1) // maxNumberOfFilesPerFolder) + 1)
|
||||||
destination = os.path.join(dirPath, destDir, file)
|
destination = os.path.join(dirPath, destDir, file)
|
||||||
shutil.move(source, destination)
|
shutil.move(source, destination)
|
||||||
fileCounter += 1
|
fileCounter += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue