I am trying to work on copying files to a different directory based on a specific file name listed in excel. I am using shutil to copy files from one directory to another directory, but it keep showing the FileNotFound.
This is the error message:
Traceback (most recent call last):
File "C:\Python\HellWorld\TestCopyPaste.py", line 20, in <module>
shutil.copytree(i, output_file, dirs_exist_ok=True)
File "C:\Users\Asus\Anaconda3\envs\untitled\lib\shutil.py", line 556, in copytree
with os.scandir(src) as itr:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'Test.pdf'
I am still new to python, please let me know if there's any part can be enhanced :)
Below are my codes:
import os
import shutil
import pandas as pd
#Set file path
input_file = "C:\\Users\\Asus\\Desktop\\Python\\Input\\"
output_file = "C:\\Users\\Asus\\Desktop\\Python\\Output\\"
#Set new variable for the file path to store the list of files
file_list = os.listdir(input_file)
#search the required file name that need to copy to another location
#Create loop to search the files
condition = pd.read_excel(r'C:\\Users\\Asus\\Desktop\\Python\Condition.xlsx')
for i in file_list:
for filename in condition:
if filename in i:
print(i)
shutil.copytree(i, output_file, dirs_exist_ok=True)