python copy_树运行,但实际上并不将目录复制到目标

python copy_树运行,但实际上并不将目录复制到目标,python,python-3.x,Python,Python 3.x,您好,我正在尝试将一个目录复制到同一台windows计算机上的另一个目录。这段代码运行时没有任何错误,但我到达了目录,它从未复制过它。这是我的密码。有什么想法吗 import File from distutils.dir_util import copy_tree if __name__ == "__main__": sourceFolder = File.File targetFolder = File.File sourceFolder.filePath =

您好,我正在尝试将一个目录复制到同一台windows计算机上的另一个目录。这段代码运行时没有任何错误,但我到达了目录,它从未复制过它。这是我的密码。有什么想法吗

import File
from distutils.dir_util import copy_tree


if __name__ == "__main__":

    sourceFolder = File.File
    targetFolder = File.File

    sourceFolder.filePath = 'C:\\Workspace\\PythonAutomation\\1-DEV\\PythonAutomation'
    targetFolder.filePath = 'C:\\Workspace\\PythonAutomation\\2-QA'


    copy_tree(sourceFolder.filePath, targetFolder.filePath)
编辑:
请注意,目录中的内容是python脚本和VisualStudio解决方案。这可能是问题所在吗?复制树只能复制某些文件类型吗?

下面是基本情况。因为你给了一个单一的、可变的对象,我猜它是一个类定义,但它不一定是多个名称,通过一个名称更改它会通过所有名称更改它

class File:
    class File:
        pass

spam = File.File
eggs = File.File

# spam and eggs refer to the *exact same thing*
assert spam is eggs

# we can lazily create a "cheese" attribute inside it
spam.cheese = 'leicester'
# but because spam and eggs are identical, this overwrites it
eggs.cheese = 'stilton'

assert spam.cheese == eggs.cheese
assert spam.cheese is eggs.cheese
这在功能上与简单情况相同:

spam = {'a': 1}
eggs = spam
eggs['a'] = 2
assert spam['a'] != 2 # fails

…你他妈的在用那个文件做什么?文件的东西?为什么您不只是在复制树'C:\\Workspace\\PythonAutomation\\1-DEV\\PythonAutomation','C:\\Workspace\\PythonAutomation\\2-QA'?什么是File.File?您可能正在覆盖File.File.filePath,因此sourceFolder.filePath和targetFolder.filePath是相同的。别那么聪明。这是我为其他项目创建的对象。在本例中没有意义,但在其他部分有意义。很抱歉造成混淆,为什么要从distutils.dir\u util中提取此函数?确实不需要吗?distutils是一种用于分发Python模块的工具。您似乎没有这样做,并且不再建议直接使用distutils,即使是针对其设计的用例。shutil是对文件和文件集合的通用操作的集合,shutil.copytree是Python中递归目录复制的常用工具。你就是炸弹。很抱歉,如果我看起来像个傻瓜,我把那个逻辑错误完全隔开了。正确创建对象例如:File.Fileattributes和stuff修复了切换到shutil.copytree时出现的错误。谢谢大家!