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

        <bdo id='I7xHa'></bdo><ul id='I7xHa'></ul>

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

        <tfoot id='I7xHa'></tfoot>
      1. <legend id='I7xHa'><style id='I7xHa'><dir id='I7xHa'><q id='I7xHa'></q></dir></style></legend>
      2. 将路径过长的文件复制到 Python 中的另一个目录

        时间:2023-08-31
      3. <legend id='MPaqz'><style id='MPaqz'><dir id='MPaqz'><q id='MPaqz'></q></dir></style></legend>

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

                  <tbody id='MPaqz'></tbody>

                <tfoot id='MPaqz'></tfoot>
                • <small id='MPaqz'></small><noframes id='MPaqz'>

                • 本文介绍了将路径过长的文件复制到 Python 中的另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Python 2.7 在 Windows 上复制文件,但有时会失败.

                  I am trying to copy files on Windows with Python 2.7, but sometimes this fails.

                  shutil.copyfile(copy_file, dest_file)
                  

                  我收到以下 IOError:

                  I get the following IOError:

                  [Errno 2] No such file or directory
                  

                  但是文件确实存在!问题是文件的路径太长.(> 255 个字符)

                  But the file does exist! The problem is that the path of the file is too long. (> 255 characters)

                  如何复制这些文件?在其他应用程序中打开它们不是问题.

                  How do I copy these files? It isn't a problem to open them in other applications.

                  要创建路径过长的文件,请创建一个文件名尽可能长的文件,并将包含的文件夹移到树结构的更深处.

                  To create a file with a too long path, create a file with an as long as possible file name and move the containing folder deeper down a tree structure.

                  我一直在尝试其中一些方法但没有成功:http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html

                  I've been trying some of these methods without success: http://timgolden.me.uk/python/win32_how_do_i/copy-a-file.html

                  推荐答案

                  我不确定 255 字符的限制,所以我偶然发现了 这篇文章.在那里我找到了一个可行的答案:在路径之前添加 \?.

                  I wasn't sure about the 255 char limit so I stumbled on this post. There I found a working answer: adding \? before the path.

                  shutil.copyfile("\\?\" + copy_file, dest_file)
                  

                  我发现使用长路径会导致 Windows 出现问题.我使用的另一个技巧是缩短路径:

                  edit: I've found that working with long paths causes issues on Windows. Another trick I use is to just shorten the paths:

                  import win32api
                  path = win32api.GetShortPathName(path)
                  

                  这篇关于将路径过长的文件复制到 Python 中的另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将一列从一个 DataFrame 复制到另一个会给出 NaN 值? 下一篇:高级索引分配是否复制数组数据?

                  相关文章

                        <bdo id='SsQq2'></bdo><ul id='SsQq2'></ul>
                    1. <legend id='SsQq2'><style id='SsQq2'><dir id='SsQq2'><q id='SsQq2'></q></dir></style></legend>

                    2. <small id='SsQq2'></small><noframes id='SsQq2'>

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