python copytree ignore some files

def ignore_function(ignore):
def _ignore_(path, names):
ignored_names = []
if ignore in names:
ignored_names.append(ignore)
return set(ignored_names)
return _ignore_

try:
shutil.copytree(src, dest, ignore=ignore_function('specificfile.file'))
except OSError as e:
if e.errno == errno.ENOTDIR:
shutil.copy(src, dst)
else:
print('Directory not copied. Error: %s' % e)

"""
ignore=ignore_patterns('*.py', '*.sh', 'specificfile.file')) <- you can use some patterns """

Leave a Reply

Your email address will not be published. Required fields are marked *