python-3.x

why my directory copy endless when run copytree command of shutil?


I have a directory like this, but when i run shutil.copytree copy my current directory to build, it copy the my directory endless?

import shutil
shutil.copytree('.' , './build') #remove build directory before.

Directory look like this:

After run copytree:
build directory is endless, i only wanted copy current directory only.


Solution

  • Shutil copytree() is called recursively.

    You have to add shutil.ignore_patterns('[pattern to build folder]') as an ignore argument to your copytree().

    See: https://docs.python.org/3/library/shutil.html#shutil.ignore_patterns