Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import os.path
- import shutil
- from pathlib import Path
- data_folder = Path("C:/Users/Folder")
- FilesFolder = Path("C:/Users/Files")
- file_to_open = data_folder / "text.txt"
- RootFolder = "TopFolder"
- NewFolderTree = data_folder / RootFolder
- with open(file_to_open) as f:
- #Striping the whitespace and extracting important parts.
- line = f.readline().strip()
- fold_location = line.split("~")[0]
- file_id = line.split(" ")[1]
- while line:
- # Iterating through files that need to be sorted.
- for file in os.listdir(FilesFolder):
- # Extracting the name, ignoring revision,extension(.zip,.pdf etc) and dashes.
- file_name = file.split('_')[0].split('-')[0].split('.')[0]
- for file_id in f:
- if file_name == file_id:
- # Check if the folder exists then copy the file to the corresponding folder in new tree.
- for root, dirs, subdirs in os.walk(NewFolderTree):
- if fold_location.exists():
- dest = Path(fold_location)
- # copy files occurs here
- shutil.copy(file, dest)
- elif not subdir.exists():
- print("Folder does not exist for " + fold_location)
- elif not file_name == file_id:
- # how do I check the next line from text file?
- # gets to end of text file.
- else:
- print('The following document is missing ' + file_name )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement