Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import os
  2.  
  3. import os.path
  4. import shutil
  5. from pathlib import Path
  6. data_folder = Path("C:/Users/Folder")
  7. FilesFolder = Path("C:/Users/Files")
  8. file_to_open = data_folder / "text.txt"
  9. RootFolder = "TopFolder"
  10. NewFolderTree = data_folder / RootFolder
  11.  
  12. with open(file_to_open) as f:
  13. #Striping the whitespace and extracting important parts.
  14. line = f.readline().strip()
  15. fold_location = line.split("~")[0]
  16. file_id = line.split(" ")[1]
  17. while line:
  18. # Iterating through files that need to be sorted.
  19. for file in os.listdir(FilesFolder):
  20. # Extracting the name, ignoring revision,extension(.zip,.pdf etc) and dashes.
  21. file_name = file.split('_')[0].split('-')[0].split('.')[0]
  22. for file_id in f:
  23. if file_name == file_id:
  24. # Check if the folder exists then copy the file to the corresponding folder in new tree.
  25. for root, dirs, subdirs in os.walk(NewFolderTree):
  26. if fold_location.exists():
  27. dest = Path(fold_location)
  28. # copy files occurs here
  29. shutil.copy(file, dest)
  30. elif not subdir.exists():
  31. print("Folder does not exist for " + fold_location)
  32.  
  33. elif not file_name == file_id:
  34. # how do I check the next line from text file?
  35.  
  36.  
  37. # gets to end of text file.
  38. else:
  39. print('The following document is missing ' + file_name )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement