我想創建一個備份程序來查找和複製所有txt文件從目錄和子目錄到另一個目錄。我是python的新手,並嘗試使用glob和shutil模塊。我將我的路徑添加到變量以使它們更易於更改。Python 3.4找到所有文件類型並複製到目錄
import os
import shutil
src= "C:/"
dest= "F:/newfolder"
src_files = os.listdir(src)
for file in src:
filename = os.path.join(src, file)
if file.endswith(".txt"):
shutil.copy(file, dest)
工作,謝謝! – axxic3