输入后缀来检索指定文件夹里的文件

# -*- coding: GBK -*-
"""
Created on Tue Jan 28 16:30:58 2014

@author: zenith
"""
import os,codecs,time
end_dict={}
files_list=[]
language=raw_input('for Chinese input 1;while English input 2--')
if language==2:
    disk=raw_input("input the file path to sort files: ")
else:
    disk=raw_input("输入文件目录(建议输入详细目录以减少检索时间): ")
end_list=['.iso','.txt','.exe','.pdf','.zip','dll','.doc','.mp3','.jpg']
for tri_tuple in os.walk(disk):
    q,w,files=tri_tuple
    files_list.extend(files)
for item in files_list:
    if item[-4:] in end_list:
        end_dict[item]=item[-3:]
suffix={'iso':'光盘镜像','txt':'文本','exe':'可执行文件','pdf':'便携文件','mp3':'音乐','jpg':'图像','zip':'真空压缩','dll':'动态链接库','doc':'word文档'}
flag=1
while flag:
    if language==2:
        search=raw_input("input the class you wanna to search: ")
    else:
        search=raw_input("输入文件后缀查找对应文件: ")
    flag=search
    search_result=[]
    for f in end_dict:
        if end_dict[f]==search:
            search_result.append(f)
    if len(search_result)!=0:
        print '\n'.join(search_result)
    else:
        if language==2:
            print 'no such file'
        else:
            print '找不到该类型文件'
time.sleep(10)
    

 

posted @ 2014-04-02 21:14  xzenith  阅读(351)  评论(0编辑  收藏  举报