Aug-08-2020, 03:24 AM
Hi,
I've recently started learning how to code in Python.
I currently have a list of filenames in a text file (Source Text File). I also have a list of folder locations in another text file (Destination). I am trying to have Python read the source text file and move the corresponding file with that name to the destination folder by reading the corresponding folder path line in the destination text file.
I am not quite sure how to go about reading the corresponding destination line to move it to the relevant folder and subfolder. Whilst running the code below I also seem to be getting an error:
FileNotFound error: [Errno 2] No such file or directory.
Any help on how to resolve this or if there are any tutorials on something similar would be appreciated.
I've recently started learning how to code in Python.
I currently have a list of filenames in a text file (Source Text File). I also have a list of folder locations in another text file (Destination). I am trying to have Python read the source text file and move the corresponding file with that name to the destination folder by reading the corresponding folder path line in the destination text file.
I am not quite sure how to go about reading the corresponding destination line to move it to the relevant folder and subfolder. Whilst running the code below I also seem to be getting an error:
FileNotFound error: [Errno 2] No such file or directory.
Any help on how to resolve this or if there are any tutorials on something similar would be appreciated.
import shutil import os cwd = os.getcwd() loc = "/Code/List.txt" dest = "/Code/Test Copy" srce = '/Code/Docs' #my_file = open(loc, "r") #content = my_file.readlines() #content_list = content.split(",") # my_file.close() # print(content) with open(loc) as my_file: for filename in my_file: file_name = filename.strip() src = r'/Code/Docs' + file_name shutil.move(src, dest + '\'' + file_name)