66

选择性拷贝-辉晖飛的博客-51CTO博客

 6 years ago
source link: http://blog.51cto.com/9473774/2067209
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

选择性拷贝

遍历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)
©著作权归作者所有:来自51CTO博客作者辉晖飛的原创作品,如需转载,请注明出处,否则将追究法律责任

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK