Make indentation style consistent (all spaces now).
This commit is contained in:
parent
a1266c6aa2
commit
dc9b46234c
|
@ -5,23 +5,23 @@ import shutil
|
||||||
|
|
||||||
|
|
||||||
def limitFilesPerFolder(folder, maxNumberOfFilesPerFolder):
|
def limitFilesPerFolder(folder, maxNumberOfFilesPerFolder):
|
||||||
for root, dirs, files in os.walk(folder, topdown=False):
|
for root, dirs, files in os.walk(folder, topdown=False):
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
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 = ((filesInFolder - 1) // maxNumberOfFilesPerFolder) + 1
|
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 = 1
|
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(((fileCounter - 1) // 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
|
||||||
|
|
||||||
|
|
||||||
|
|
66
recovery.py
66
recovery.py
|
@ -15,31 +15,31 @@ def getNumberOfFilesInFolderRecursively(start_path = '.'):
|
||||||
for f in filenames:
|
for f in filenames:
|
||||||
fp = os.path.join(dirpath, f)
|
fp = os.path.join(dirpath, f)
|
||||||
if(os.path.isfile(fp)):
|
if(os.path.isfile(fp)):
|
||||||
numberOfFiles += 1
|
numberOfFiles += 1
|
||||||
return numberOfFiles
|
return numberOfFiles
|
||||||
|
|
||||||
|
|
||||||
def getNumberOfFilesInFolder(path):
|
def getNumberOfFilesInFolder(path):
|
||||||
return len(os.listdir(path))
|
return len(os.listdir(path))
|
||||||
|
|
||||||
|
|
||||||
def log(logString):
|
def log(logString):
|
||||||
print(strftime("%H:%M:%S", localtime()) + ": " + logString)
|
print(strftime("%H:%M:%S", localtime()) + ": " + logString)
|
||||||
|
|
||||||
|
|
||||||
def moveFile(file, destination):
|
def moveFile(file, destination):
|
||||||
extension = os.path.splitext(file)[1][1:].upper()
|
extension = os.path.splitext(file)[1][1:].upper()
|
||||||
sourcePath = os.path.join(root, file)
|
sourcePath = os.path.join(root, file)
|
||||||
|
|
||||||
destinationDirectory = os.path.join(destination, extension)
|
destinationDirectory = os.path.join(destination, extension)
|
||||||
|
|
||||||
if not os.path.exists(destinationDirectory):
|
if not os.path.exists(destinationDirectory):
|
||||||
os.mkdir(destinationDirectory)
|
os.mkdir(destinationDirectory)
|
||||||
|
|
||||||
fileName = str(fileCounter) + "." + extension.lower()
|
fileName = str(fileCounter) + "." + extension.lower()
|
||||||
destinationFile = os.path.join(destinationDirectory, fileName)
|
destinationFile = os.path.join(destinationDirectory, fileName)
|
||||||
if not os.path.exists(destinationFile):
|
if not os.path.exists(destinationFile):
|
||||||
shutil.copy(sourcePath, destinationFile)
|
shutil.copy(sourcePath, destinationFile)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,20 +48,20 @@ source = None
|
||||||
destination = None
|
destination = None
|
||||||
|
|
||||||
if(len(sys.argv) < 3):
|
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:
|
else:
|
||||||
source = sys.argv[1]
|
source = sys.argv[1]
|
||||||
print("Source directory: " + source)
|
print("Source directory: " + source)
|
||||||
destination = sys.argv[2]
|
destination = sys.argv[2]
|
||||||
print("Destination directory: " + destination)
|
print("Destination directory: " + destination)
|
||||||
|
|
||||||
if(len(sys.argv) > 3):
|
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))):
|
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))):
|
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)
|
fileNumber = getNumberOfFilesInFolderRecursively(source)
|
||||||
onePercentFiles = int(fileNumber/100)
|
onePercentFiles = int(fileNumber/100)
|
||||||
|
@ -72,23 +72,23 @@ print("Files to copy: " + totalAmountToCopy)
|
||||||
fileCounter = 0
|
fileCounter = 0
|
||||||
for root, dirs, files in os.walk(source, topdown=False):
|
for root, dirs, files in os.walk(source, topdown=False):
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
extension = os.path.splitext(file)[1][1:].upper()
|
extension = os.path.splitext(file)[1][1:].upper()
|
||||||
sourcePath = os.path.join(root, file)
|
sourcePath = os.path.join(root, file)
|
||||||
|
|
||||||
destinationDirectory = os.path.join(destination, extension)
|
destinationDirectory = os.path.join(destination, extension)
|
||||||
|
|
||||||
if not os.path.exists(destinationDirectory):
|
if not os.path.exists(destinationDirectory):
|
||||||
os.mkdir(destinationDirectory)
|
os.mkdir(destinationDirectory)
|
||||||
|
|
||||||
fileName = str(fileCounter) + "." + extension.lower()
|
fileName = str(fileCounter) + "." + extension.lower()
|
||||||
destinationFile = os.path.join(destinationDirectory, fileName)
|
destinationFile = os.path.join(destinationDirectory, fileName)
|
||||||
if not os.path.exists(destinationFile):
|
if not os.path.exists(destinationFile):
|
||||||
shutil.copy2(sourcePath, destinationFile)
|
shutil.copy2(sourcePath, destinationFile)
|
||||||
|
|
||||||
fileCounter += 1
|
fileCounter += 1
|
||||||
if((fileCounter % onePercentFiles) is 0):
|
if((fileCounter % onePercentFiles) is 0):
|
||||||
log(str(fileCounter) + " / " + totalAmountToCopy + " processed.")
|
log(str(fileCounter) + " / " + totalAmountToCopy + " processed.")
|
||||||
|
|
||||||
log("start special file treatment")
|
log("start special file treatment")
|
||||||
jpgSorter.postprocessImages(os.path.join(destination, "JPG"), False)
|
jpgSorter.postprocessImages(os.path.join(destination, "JPG"), False)
|
||||||
|
|
Loading…
Reference in New Issue