在我的项目中,我创建了一个函数,用于以循环模式将文件夹从路径复制到另一个路径,如下所示:
def copytree(src, dst, symlinks=False, ignore=None):
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
shutil.copytree(s, d, symlinks, ignore)
else:
shutil.copy2(s, d)
for root, subdirs, files in os.walk(d):
for filename in files:
print("To->",os.path.join(root, filename))
如果我在 linux 服务器上运行我的代码,所有工作都已完成,但如果我在 Windows 上运行,则该函数仅复制原始文件夹中的最后一个文件。
如何使此功能适用于所有文件系统?
提前致谢