如何在shuil.copy中为ignore编写回调函数

2024-07-08 16:07:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python比较陌生。我正试图将一个目录复制到维护该结构的另一个目录。

我在用

    shutil.copytree(src, dst, symlinks=False, ignore=None, 
    copy_function=copy2, ignore_dangling_symlinks=False)

我试图为ignore编写一个回调函数。

我的目标是获取列表中的文件列表,只复制这些文件,而忽略其余文件。如何将列表传递给回调函数?

我写了一个简单的回调函数,但是当我试图运行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

Tags: 文件函数insrc目录false列表names

热门问题