<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 版)脚本中的文件夹中?

      How do I copy files with specific file extension to a folder in my python (version 2.5) script?(如何将具有特定文件扩展名的文件复制到我的 python(2.5 版)脚本中的文件夹中?)
        <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 版)脚本中的文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                How to extend Python class init(如何扩展 Python 类初始化)
                What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                Initialize list with same bool value(使用相同的布尔值初始化列表)
                setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

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

                    • <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'>