I have been struggling for a couple of hours trying to suss this out. I have parsed directories and files to find which files I want to copy to somewhere else. I have this:
Code:
for aFile in os.listdir(thispath):
aPath = os.path.join(thispath, aFile)
print aPath
dest = thispath
vs = thispath.split(rootdir).pop()
dPath = os.path.join(destination_root,vs)
print destination_root + vs
print dPath
Although aPath is fine and
destination_root + vs
prints out correctly, dPath is just vs
vs is taking the Path of the files in the directory I'm copying and stripping out the start directory I am parsing from. So why doesn't this line:
dPath = os.path.join(destination_root,value)
Give me the same as destination_root + value ?
I want that to be right so I can use:
Code:
if os.path.isfile(aPath):
shutil.copy(aPath,dPath)
Or maybe in other words how do I take a valid string and turn it into something shutil.copy will recognise as a valid directory?!
Hope that makes sense! Thanks