标签:shutil 扩展 file path env join for class 目录
遍历work目录及子目录中扩展名为txt的文件,将它们拷贝到一个新的文件夹work_txt中#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shutil
spath = 'f:\\work'
dpath = 'f:\\work_txt'
if not os.path.exists(dpath):
os.mkdir(dpath)
for root, dirs, files in os.walk(spath):
for f in files:
if f.endswith('.txt'):
print(os.path.join(root, f))
txt = os.path.join(root, f)
shutil.copy(txt, dpath)标签:shutil 扩展 file path env join for class 目录
原文地址:http://blog.51cto.com/9473774/2067209