a guest Dec 17th, 2015 20 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- import shutil, os
- #Returns a file's new name based on the number of files in the destination folder.
- #If there's no pictures, it's renamed name0, if there's 100, it's renamed name100.
- def renameFile(source, destination):
- numberOfFiles = 0
- for item in os.listdir(destination):
- numberOfFiles += 1
- newName = (os.path.splitext(source)).split('%') + str(numberOfFiles) + os.path.splitext(source)
- os.rename(source, newName)
- return newName
- #Moves file from one location to another, with a new name.
- def moveFile(source, destination):
- filename = source
- filename = renameFile(filename, destination)
- shutil.move(filename, destination)
- #Moves files in current directory into repsective folders.
- #Makes folders if they don't exist.
- #Doesn't move a file if another file in the target directory is the same size in bytes,
- #as a rudimentary form of preventing duplicate pictures.
- def organizePictures():
- for item in os.listdir(os.getcwd()):
- if not os.path.isdir(item) and not item.endswith('.py') and not item.endswith('.pyw'):
- folderName = (os.path.splitext(item)).translate(None, '%') + " Folder"
- folderSizes = 
- if not os.path.isdir(folderName):
- for picFile in os.listdir(folderName):
- folderSizes.append(os.stat(folderName + "\\" + picFile).st_size)
- if os.stat(item).st_size not in folderSizes:
- moveFile(item, folderName)
RAW Paste Data