Include source folder when using shutil.copyree

Viewed 11

I want to copy folders from folder f1 with the structure A/B/C/D/E to a destination folder, f2, which will include C/D/E based on conditions given in a pandas df.

So far, I am able to copy folders from f1 using the path A/B/C to f2. However, in f2, the folders begin from D/E onwards. Is there a way to copy the last folder in a file path to f2 so the folder structure is C/D/E?

So far, I have

root_archive = Path(archive)
for file_path in Path(root_archive).glob('*'):
    for c in df_inner['Reference']:
        if c in str(file_path):
            shutil.copytree(file_path, Path(workingfolder), dirs_exist_ok=True)

Where file_path = A/B/C and the name C is being used as the Reference in 'for c in df_inner['Reference']'.

Thank you for any input.

0 Answers
Related