#!/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)原文:http://blog.51cto.com/9473774/2067209