Make indentation style consistent (all spaces now).

This commit is contained in:
Wouter R 2017-11-25 19:24:30 +01:00
parent a1266c6aa2
commit dc9b46234c
2 changed files with 51 additions and 51 deletions

View File

@ -5,23 +5,23 @@ import shutil
def limitFilesPerFolder(folder, maxNumberOfFilesPerFolder):
for root, dirs, files in os.walk(folder, topdown=False):
for dir in dirs:
dirPath = os.path.join(root, dir)
filesInFolder = len(os.listdir(dirPath))
if(filesInFolder > maxNumberOfFilesPerFolder):
numberOfSubfolders = ((filesInFolder - 1) // maxNumberOfFilesPerFolder) + 1
for subFolderNumber in range(1, numberOfSubfolders+1):
subFolderPath = os.path.join(dirPath, str(subFolderNumber))
if not os.path.exists(subFolderPath):
os.mkdir(subFolderPath)
fileCounter = 1
for file in os.listdir(dirPath):
source = os.path.join(dirPath, file)
if os.path.isfile(source):
destDir = str(((fileCounter - 1) // maxNumberOfFilesPerFolder) + 1)
destination = os.path.join(dirPath, destDir, file)
shutil.move(source, destination)
fileCounter += 1
for root, dirs, files in os.walk(folder, topdown=False):
for dir in dirs:
dirPath = os.path.join(root, dir)
filesInFolder = len(os.listdir(dirPath))
if(filesInFolder > maxNumberOfFilesPerFolder):
numberOfSubfolders = ((filesInFolder - 1) // maxNumberOfFilesPerFolder) + 1
for subFolderNumber in range(1, numberOfSubfolders+1):
subFolderPath = os.path.join(dirPath, str(subFolderNumber))
if not os.path.exists(subFolderPath):
os.mkdir(subFolderPath)
fileCounter = 1
for file in os.listdir(dirPath):
source = os.path.join(dirPath, file)
if os.path.isfile(source):
destDir = str(((fileCounter - 1) // maxNumberOfFilesPerFolder) + 1)
destination = os.path.join(dirPath, destDir, file)
shutil.move(source, destination)
fileCounter += 1

View File

@ -15,31 +15,31 @@ def getNumberOfFilesInFolderRecursively(start_path = '.'):
for f in filenames:
fp = os.path.join(dirpath, f)
if(os.path.isfile(fp)):
numberOfFiles += 1
numberOfFiles += 1
return numberOfFiles
def getNumberOfFilesInFolder(path):
return len(os.listdir(path))
return len(os.listdir(path))
def log(logString):
print(strftime("%H:%M:%S", localtime()) + ": " + logString)
print(strftime("%H:%M:%S", localtime()) + ": " + logString)
def moveFile(file, destination):
extension = os.path.splitext(file)[1][1:].upper()
sourcePath = os.path.join(root, file)
extension = os.path.splitext(file)[1][1:].upper()
sourcePath = os.path.join(root, file)
destinationDirectory = os.path.join(destination, extension)
destinationDirectory = os.path.join(destination, extension)
if not os.path.exists(destinationDirectory):
os.mkdir(destinationDirectory)
if not os.path.exists(destinationDirectory):
os.mkdir(destinationDirectory)
fileName = str(fileCounter) + "." + extension.lower()
destinationFile = os.path.join(destinationDirectory, fileName)
if not os.path.exists(destinationFile):
shutil.copy(sourcePath, destinationFile)
fileName = str(fileCounter) + "." + extension.lower()
destinationFile = os.path.join(destinationDirectory, fileName)
if not os.path.exists(destinationFile):
shutil.copy(sourcePath, destinationFile)
@ -48,20 +48,20 @@ source = None
destination = None
if(len(sys.argv) < 3):
print("Enter source and destination: python sort.py source/path destination/path")
print("Enter source and destination: python sort.py source/path destination/path")
else:
source = sys.argv[1]
print("Source directory: " + source)
destination = sys.argv[2]
print("Destination directory: " + destination)
source = sys.argv[1]
print("Source directory: " + source)
destination = sys.argv[2]
print("Destination directory: " + destination)
if(len(sys.argv) > 3):
maxNumberOfFilesPerFolder = int(sys.argv[3])
maxNumberOfFilesPerFolder = int(sys.argv[3])
while ((source is None) or (not os.path.exists(source))):
source = input('Enter a valid source directory\n')
source = input('Enter a valid source directory\n')
while ((destination is None) or (not os.path.exists(destination))):
destination = input('Enter a valid destination directory\n')
destination = input('Enter a valid destination directory\n')
fileNumber = getNumberOfFilesInFolderRecursively(source)
onePercentFiles = int(fileNumber/100)
@ -72,23 +72,23 @@ print("Files to copy: " + totalAmountToCopy)
fileCounter = 0
for root, dirs, files in os.walk(source, topdown=False):
for file in files:
extension = os.path.splitext(file)[1][1:].upper()
sourcePath = os.path.join(root, file)
for file in files:
extension = os.path.splitext(file)[1][1:].upper()
sourcePath = os.path.join(root, file)
destinationDirectory = os.path.join(destination, extension)
destinationDirectory = os.path.join(destination, extension)
if not os.path.exists(destinationDirectory):
os.mkdir(destinationDirectory)
if not os.path.exists(destinationDirectory):
os.mkdir(destinationDirectory)
fileName = str(fileCounter) + "." + extension.lower()
destinationFile = os.path.join(destinationDirectory, fileName)
if not os.path.exists(destinationFile):
shutil.copy2(sourcePath, destinationFile)
fileName = str(fileCounter) + "." + extension.lower()
destinationFile = os.path.join(destinationDirectory, fileName)
if not os.path.exists(destinationFile):
shutil.copy2(sourcePath, destinationFile)
fileCounter += 1
if((fileCounter % onePercentFiles) is 0):
log(str(fileCounter) + " / " + totalAmountToCopy + " processed.")
fileCounter += 1
if((fileCounter % onePercentFiles) is 0):
log(str(fileCounter) + " / " + totalAmountToCopy + " processed.")
log("start special file treatment")
jpgSorter.postprocessImages(os.path.join(destination, "JPG"), False)