#!/usr/bin/env python
#-*- encoding:utf8 -*-
import wx
import os,os.path,itertools
import re
import wmi
def getdiskpart():
diskpartlist=[]
c = wmi.WMI()
for physical_disk in c.Win32_DiskDrive():
for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
diskpartlist.append(logical_disk.Caption)
return diskpartlist
a=[]
class MenuEventFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, u'文件查找')
panel=wx.Panel(self)
searchpath=wx.StaticText(panel,-1,u'路径',pos=(-1,-1),size=(50,30))
self.pathvalue=wx.TextCtrl(panel,-1,'',pos=(searchpath.GetSize().width,0),size=(200,30))
fileformat=wx.StaticText(panel,-1,u'文件格式',pos=(0,30),size=(50,30))
self.fromatvalue=wx.TextCtrl(panel,-1,'',pos=(fileformat.GetSize().width,30),size=(200,30))
button=wx.Button(panel,-1,u'查询',pos=(0,60),size=(50,30))
self.Bind(wx.EVT_BUTTON,self.OnClick,button)
def OnClick(self,event):
global a
value=self.fromatvalue.GetValue().encode("gbk").split()
if self.pathvalue.GetValue().encode("gbk")=='':
#path=self.pathvalue.GetValue().encode("gbk")
for dirr in getdiskpart():
path=dirr
#path=self.pathvalue.GetValue().encode("gbk")
path=dirr+'\\'
path=replance(path)
searchfile(path,value)
print '#'*40
for x in a:
print x
print '#'*40
a=[]
else:
path=self.pathvalue.GetValue().encode("gbk")
path+='\\'
path=replance(path)
if not os.path.isdir(path):
print '请输入正确的路径'.decode('utf8')
a=[]
return
searchfile(path,value)
print '#'*40
for x in a:
print x
print '#'*40
a=[]
def anyTrue(filename, sequence):
return True in itertools.imap(filename.endswith, sequence)
def searchfile(path,*endswithformate):
for basedir,dirlist,filenames in os.walk(path):
for x in filenames:
if anyTrue(x,endswithformate[0]):
a.append(basedir+'\\'+x)
return a
def replance(text):
#rx=re.compile('|'.join(map(re.escape,adict)))
rx=re.compile(r'\\')
# def replancedstr(macth):
# '''sub中的替换函数,只能是macth对象
# '''
# return adict[macth.group()]
return rx.sub('\\\\',text)
if __name__ == '__main__':
app = wx.App()
frame. = MenuEventFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()