Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. def organizer(folder):
  2. import glob, os, shutil
  3.  
  4.  
  5. file_destinations = {
  6. 'main': 'C:/Users/luisc/Documents/Scan',
  7. 'check': 'C:/Users/luisc/Documents/Scan/Check',
  8. 'timesheet': 'C:/Users/luisc/Documents/Scan/Timesheet'
  9. }
  10.  
  11. def organizer(folder):
  12. destination = file_destinations.get(folder)
  13. if destination:
  14. os.chdir(destination)
  15. else:
  16. print ('{0} is not a valid option'.format(folder))
  17. return
  18.  
  19. for file in glob.glob('*'):
  20. file_parts = file.split(' ')
  21. if not os.path.isdir(file):
  22. if folder.lower() == 'main':
  23. ref = file_parts[0]
  24. elif folder.lower() == 'check':
  25. ref = file_parts[1]
  26. elif folder.lower() == 'timesheet':
  27. ref = '{0} {1}'.format(file_parts[1], file_parts[2])
  28. else:
  29. print('{0} is not a valid file'.format(file))
  30. return
  31.  
  32. source = '{0}/{1}'.format(os.path.dirname(os.path.realpath(__file__)), file)
  33. destination = '{0}/{1}/{2}'.format(os.path.dirname(os.path.realpath(__file__)), ref, file)
  34.  
  35. # move file or create folder then move file
  36. if not os.path.exists(ref):
  37. os.makedirs(ref)
  38. shutil.move(source, destination)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement