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

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

    1. <tfoot id='JVCec'></tfoot>
        <bdo id='JVCec'></bdo><ul id='JVCec'></ul>
    2. <legend id='JVCec'><style id='JVCec'><dir id='JVCec'><q id='JVCec'></q></dir></style></legend>

      如何将具有特定文件扩展名的文件复制到我的 python(2.5 版)脚本中的文件夹中?

      时间:2023-08-31
        <i id='FwLjS'><tr id='FwLjS'><dt id='FwLjS'><q id='FwLjS'><span id='FwLjS'><b id='FwLjS'><form id='FwLjS'><ins id='FwLjS'></ins><ul id='FwLjS'></ul><sub id='FwLjS'></sub></form><legend id='FwLjS'></legend><bdo id='FwLjS'><pre id='FwLjS'><center id='FwLjS'></center></pre></bdo></b><th id='FwLjS'></th></span></q></dt></tr></i><div id='FwLjS'><tfoot id='FwLjS'></tfoot><dl id='FwLjS'><fieldset id='FwLjS'></fieldset></dl></div>
        • <bdo id='FwLjS'></bdo><ul id='FwLjS'></ul>

          <legend id='FwLjS'><style id='FwLjS'><dir id='FwLjS'><q id='FwLjS'></q></dir></style></legend>

                <tbody id='FwLjS'></tbody>
              1. <small id='FwLjS'></small><noframes id='FwLjS'>

                <tfoot id='FwLjS'></tfoot>

                本文介绍了如何将具有特定文件扩展名的文件复制到我的 python(2.5 版)脚本中的文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想将具有特定文件扩展名的文件复制到新文件夹.我知道如何使用 os.walk 但具体来说我将如何使用它?我只在一个文件夹中搜索具有特定文件扩展名的文件(此文件夹有 2 个子目录,但我要查找的文件永远不会在这 2 个子目录中找到,因此我不需要在这些子目录中搜索).提前致谢.

                I'd like to copy the files that have a specific file extension to a new folder. I have an idea how to use os.walk but specifically how would I go about using that? I'm searching for the files with a specific file extension in only one folder (this folder has 2 subdirectories but the files I'm looking for will never be found in these 2 subdirectories so I don't need to search in these subdirectories). Thanks in advance.

                推荐答案

                import glob, os, shutil
                
                files = glob.iglob(os.path.join(source_dir, "*.ext"))
                for file in files:
                    if os.path.isfile(file):
                        shutil.copy2(file, dest_dir)
                

                阅读shutil模块的文档选择适合您需要的函数(shutil.copy()、shutil.copy2() 或 shutil.copyfile()).

                Read the documentation of the shutil module to choose the function that fits your needs (shutil.copy(), shutil.copy2() or shutil.copyfile()).

                这篇关于如何将具有特定文件扩展名的文件复制到我的 python(2.5 版)脚本中的文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在python中深度复制队列 下一篇:python脚本将目录中的所有文件连接到一个文件中

                相关文章

                  <legend id='J07Mr'><style id='J07Mr'><dir id='J07Mr'><q id='J07Mr'></q></dir></style></legend>

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

                  <tfoot id='J07Mr'></tfoot>
                  • <bdo id='J07Mr'></bdo><ul id='J07Mr'></ul>

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