码迷,mamicode.com
首页 > 编程语言 > 详细

python工具程序一、复制目录中指定扩展名的文件

时间:2016-01-27 21:06:23      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

#!/usr/bin/env python
# coding:utf-8

# xcopy Lib directory and rename all files to *d.lib

import os
from os.path import join,exists
import shutil
from win32com.shell import shell, shellcon
from msvcrt import getch

root_path = r"E:\workspace\Src"
origLibpath = root_path + r"\vc\Lib\lib18x64"
newLibpath = root_path + r"\libd\lib18x64"

if not exists(origLibpath):
    print("Can‘t find original libs!")
else:
    if os.path.exists(newLibpath):
        shutil.rmtree(newLibpath)
        
    for path, dirs, files in os.walk(origLibpath):
        for pre_fname in files:
            if not pre_fname.endswith(‘.lib‘):
                continue
            new_fname = pre_fname.replace(‘.‘, ‘d.‘)
            pre_fullname = join(path, pre_fname)
            new_fullname = join(path.replace(origLibpath, newLibpath), new_fname)
            shell.SHFileOperation((0, shellcon.FO_COPY, pre_fullname, new_fullname, shellcon.FOF_NOCONFIRMMKDIR, None, None))
    origLibpath = r"D:\devenv\Lib\vc90x64"
    newLibpath = root_path + r"\libd\vc90x64"
    for path, dirs, files in os.walk(origLibpath):
        for pre_fname in files:
            if not pre_fname.endswith(‘.lib‘):
                continue
            new_fname = pre_fname.replace(‘.‘, ‘d.‘)
            pre_fullname = join(path, pre_fname)
            new_fullname = join(path.replace(origLibpath, newLibpath), new_fname)
            shell.SHFileOperation((0, shellcon.FO_COPY, pre_fullname, new_fullname, shellcon.FOF_NOCONFIRMATION|shellcon.FOF_NOCONFIRMMKDIR, None, None))
    print("已复制了两处 Lib目录,文件重命名加d!")
    print("按任意键退出。")
    getch()

  

python工具程序一、复制目录中指定扩展名的文件

标签:

原文地址:http://www.cnblogs.com/shankun/p/5164268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!