• <legend id='mmQWc'><style id='mmQWc'><dir id='mmQWc'><q id='mmQWc'></q></dir></style></legend>
    <tfoot id='mmQWc'></tfoot>

    <small id='mmQWc'></small><noframes id='mmQWc'>

      <i id='mmQWc'><tr id='mmQWc'><dt id='mmQWc'><q id='mmQWc'><span id='mmQWc'><b id='mmQWc'><form id='mmQWc'><ins id='mmQWc'></ins><ul id='mmQWc'></ul><sub id='mmQWc'></sub></form><legend id='mmQWc'></legend><bdo id='mmQWc'><pre id='mmQWc'><center id='mmQWc'></center></pre></bdo></b><th id='mmQWc'></th></span></q></dt></tr></i><div id='mmQWc'><tfoot id='mmQWc'></tfoot><dl id='mmQWc'><fieldset id='mmQWc'></fieldset></dl></div>

        • <bdo id='mmQWc'></bdo><ul id='mmQWc'></ul>

      1. 如何在python中递归复制目录并覆盖全部?

        时间:2023-08-31
          <bdo id='30Wa4'></bdo><ul id='30Wa4'></ul>

          • <i id='30Wa4'><tr id='30Wa4'><dt id='30Wa4'><q id='30Wa4'><span id='30Wa4'><b id='30Wa4'><form id='30Wa4'><ins id='30Wa4'></ins><ul id='30Wa4'></ul><sub id='30Wa4'></sub></form><legend id='30Wa4'></legend><bdo id='30Wa4'><pre id='30Wa4'><center id='30Wa4'></center></pre></bdo></b><th id='30Wa4'></th></span></q></dt></tr></i><div id='30Wa4'><tfoot id='30Wa4'></tfoot><dl id='30Wa4'><fieldset id='30Wa4'></fieldset></dl></div>

            1. <tfoot id='30Wa4'></tfoot>
              1. <legend id='30Wa4'><style id='30Wa4'><dir id='30Wa4'><q id='30Wa4'></q></dir></style></legend>

                  <tbody id='30Wa4'></tbody>
                • <small id='30Wa4'></small><noframes id='30Wa4'>

                  本文介绍了如何在python中递归复制目录并覆盖全部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将 /home/myUser/dir1/ 及其所有内容(及其内容等)复制到 /home/myuser/dir2/在蟒蛇.此外,我希望副本覆盖 dir2/ 中的所有内容.

                  I'm trying to copy /home/myUser/dir1/ and all its contents (and their contents, etc.) to /home/myuser/dir2/ in python. Furthermore, I want the copy to overwrite everything in dir2/.

                  看起来distutils.dir_util.copy_tree 可能是适合这项工作的工具,但不确定是否有任何更容易/更明显的工具用于如此简单任务.

                  It looks like distutils.dir_util.copy_tree might be the right tool for the job, but not sure if there's anything easier/more obvious to use for such a simple task.

                  如果它是正确的工具,我该如何使用它?根据 docs 有 8 个参数.我是否必须通过所有 8 个只是 srcdstupdate,如果是,如何(我是 Python 新手).

                  If it is the right tool, how do I use it? According to the docs there are 8 parameters that it takes. Do I have to pass all 8 are just src, dst and update, and if so, how (I'm brand new to Python).

                  如果有更好的东西,有人可以给我一个例子并指出正确的方向吗?提前致谢!

                  If there's something out there that's better, can someone give me an example and point me in the right direction? Thanks in advance!

                  推荐答案

                  你可以使用 distutils.dir_util.copy_tree.它工作得很好,你不必传递每个参数,只有 srcdst 是强制性的.

                  You can use distutils.dir_util.copy_tree. It works just fine and you don't have to pass every argument, only src and dst are mandatory.

                  但是,在您的情况下,您不能使用像 shutil.copytree 这样的类似工具,因为它的行为不同:由于目标目录不能存在,因此该函数不能用于覆盖其内容.

                  However in your case you can't use a similar tool likeshutil.copytree because it behaves differently: as the destination directory must not exist this function can't be used for overwriting its contents.

                  如果您想按照问题评论中的建议使用 cp 工具,请注意使用 subprocess 模块目前是生成新进程的推荐方式,如您所见在 os.system 函数的文档中.

                  If you want to use the cp tool as suggested in the question comments beware that using the subprocess module is currently the recommended way for spawning new processes as you can see in the documentation of the os.system function.

                  这篇关于如何在python中递归复制目录并覆盖全部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何制作复杂列表的完全非共享副本?(深拷贝是不够的) 下一篇:如何使用openpyxl将工作表从一个工作簿复制到另一个工作簿?

                  相关文章

                  <legend id='okLiw'><style id='okLiw'><dir id='okLiw'><q id='okLiw'></q></dir></style></legend>
                  <i id='okLiw'><tr id='okLiw'><dt id='okLiw'><q id='okLiw'><span id='okLiw'><b id='okLiw'><form id='okLiw'><ins id='okLiw'></ins><ul id='okLiw'></ul><sub id='okLiw'></sub></form><legend id='okLiw'></legend><bdo id='okLiw'><pre id='okLiw'><center id='okLiw'></center></pre></bdo></b><th id='okLiw'></th></span></q></dt></tr></i><div id='okLiw'><tfoot id='okLiw'></tfoot><dl id='okLiw'><fieldset id='okLiw'></fieldset></dl></div>
                  <tfoot id='okLiw'></tfoot>

                    <small id='okLiw'></small><noframes id='okLiw'>

                      • <bdo id='okLiw'></bdo><ul id='okLiw'></ul>