From dc9b46234ce2df11aa9b4976305e1ebefb57328d Mon Sep 17 00:00:00 2001 From: Wouter R Date: Sat, 25 Nov 2017 19:24:30 +0100 Subject: [PATCH] Make indentation style consistent (all spaces now). --- numberOfFilesPerFolderLimiter.py | 36 ++++++++--------- recovery.py | 66 ++++++++++++++++---------------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/numberOfFilesPerFolderLimiter.py b/numberOfFilesPerFolderLimiter.py index f226bf0..fc60d2a 100644 --- a/numberOfFilesPerFolderLimiter.py +++ b/numberOfFilesPerFolderLimiter.py @@ -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 diff --git a/recovery.py b/recovery.py index c926933..b283203 100644 --- a/recovery.py +++ b/recovery.py @@ -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)