[Python] Filter directory when using shutil.copytree?

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a way I can filter a directory by using the absolute path to it?

    shutil.copytree(directory,
    target_dir,
    ignore = shutil.ignore_patterns("/Full/Path/To/aDir/Common"))


    This doesn't seem to work when trying to filter the "Common" Directory located under "aDir". If I do this:

    shutil.copytree(directory,
    target_dir,
    ignore = shutil.ignore_patterns("Common"))


    It works, but every directory called Common will be filtered in that "tree", which is not what I want.

    Any suggestions ?

    Thanks.

    Continue reading...

Compartilhe esta Página