I want to automate copying directory contents to another folder. I found this post (Copy directory contents into a directory with python) and would like to make it so that I can run a for loop. This is my code so far, however I am getting an error saying cannot copy tree because 'X' is not a directory where 'X' is the filepath of the directory I want to copy.
I tried running copy_tree once manually by simply copying the first value from my imported file list and it works. Where did I go wrong? Thanks.
from distutils.dir_util import copy_tree
import os
location = 'C:/users/trinhsk/desktop/out_space.txt'
with open(location,'r') as f:
fromDirectory = f.readlines()
for i in fromDirectory:
bsname = os.path.basename(os.path.dirname(os.path.dirname(i)))
copy_tree(str(i), "H:/spectraDB_copy/{}/".format(bsname))