我对Python比较新。我正在尝试复制一个目录到另一个目录并保持结构。
我正在使用
shutil.copytree(src, dst, symlinks=False, ignore=None,
copy_function=copy2, ignore_dangling_symlinks=False)
我正在尝试编写一个忽略的回调函数。
我的目标是获取文件列表,并仅复制这些文件,而忽略其余文件。如何将列表传递给回调函数?
我编写了一个简单的回调函数,但是当我尝试运行copyTree函数时会出现一些错误。
def abc(src,names):
print(src)
print(names)
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
shutil.copytree('D:\Mytest','D:\PythonTestDest3',symlinks=False,ignore=abc)
File "C:\Python32\lib\shutil.py", line 204, in copytree
if name in ignored_names:
TypeError: argument of type 'NoneType' is not iterable
return [f for f in files if not is_dir(os.path.join(folder, f)) and f not in copy_these]
。 - Fred Foo