我正在学习python(python 3),我可以通过执行此操作将1个文件复制到新目录
import shutil
shutil.copyfile('C:/test/test.txt', 'C:/lol/test.txt')
Run Code Online (Sandbox Code Playgroud)
我现在要做的是将所有*.txt文件从C:/复制到C:/ test
*.txt是一个通配符,用于搜索硬盘上的所有文本文件
我试图弄清楚如何将CAD图纸(".dwg",".dxf")从包含子文件夹的源目录复制到目标目录,并维护原始目录和子文件夹结构.
我在以下帖子中找到了@martineau的以下答案:Python Factory Function
from fnmatch import fnmatch, filter
from os.path import isdir, join
from shutil import copytree
def include_patterns(*patterns):
"""Factory function that can be used with copytree() ignore parameter.
Arguments define a sequence of glob-style patterns
that are used to specify what files to NOT ignore.
Creates and returns a function that determines this for each directory
in the file hierarchy rooted at the source directory when used with
shutil.copytree(). …Run Code Online (Sandbox Code Playgroud)