Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def organizer(folder):
- import glob, os, shutil
- file_destinations = {
- 'main': 'C:/Users/luisc/Documents/Scan',
- 'check': 'C:/Users/luisc/Documents/Scan/Check',
- 'timesheet': 'C:/Users/luisc/Documents/Scan/Timesheet'
- }
- def organizer(folder):
- destination = file_destinations.get(folder)
- if destination:
- os.chdir(destination)
- else:
- print ('{0} is not a valid option'.format(folder))
- return
- for file in glob.glob('*'):
- file_parts = file.split(' ')
- if not os.path.isdir(file):
- if folder.lower() == 'main':
- ref = file_parts[0]
- elif folder.lower() == 'check':
- ref = file_parts[1]
- elif folder.lower() == 'timesheet':
- ref = '{0} {1}'.format(file_parts[1], file_parts[2])
- else:
- print('{0} is not a valid file'.format(file))
- return
- source = '{0}/{1}'.format(os.path.dirname(os.path.realpath(__file__)), file)
- destination = '{0}/{1}/{2}'.format(os.path.dirname(os.path.realpath(__file__)), ref, file)
- # move file or create folder then move file
- if not os.path.exists(ref):
- os.makedirs(ref)
- shutil.move(source, destination)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement