我正在尝试编写一个简单的脚本来将文件从一个文件夹移动到另一个文件夹并过滤掉不必要的东西。我正在使用下面的代码,但收到错误
import shutil
import errno
def copy(src, dest):
try:
shutil.copytree(src, dest, ignore=shutil.ignore_patterns('*.mp4', '*.bak'))
except OSError:
if OSError.errno == errno.ENOTDIR:
shutil.copy(src, dest)
else:
print("Directory not copied. Error: %s" % OSError)
src = raw_input("Please enter a source: ")
dest = raw_input("Please enter a destination: ")
copy(src, dest)
我得到的错误是:
Traceback (most recent call last):
File "/Users/XXX/PycharmProjects/Folders/Fold.py", line 29,
in <module>
copy(src, dest)
File "/Users/XXX/PycharmProjects/Folders/Fold.py", line 17,
in copy
ignore_pat = shutil.ignore_patterns('*.mp4', '*.bak')
AttributeError: 'module' object has no attribute 'ignore_patterns'