Python3.2完成简单文件搜索的代码,python3.2搜索代码,这是依赖python 3
Python3.2完成简单文件搜索的代码,python3.2搜索代码,这是依赖python 3
这是依赖python 3.2来完成的简单文件搜索的方法。希望大牛们能帮我再改进下代码。
程序中我用到了python os\time、python re、pythonthreading多线程模块。
import osimport timeimport reimport threadingclass brid: def __init__(self): th=threading.Thread(target=self.dt(),args="") th.start() threading.Thread.join(th) pass def dt(self): a=True while a is True: print("xx") time.sleep(3) a=False def FileSearch(self,keywords,path): print("searching...") results=[] i=0 j=0 time_start=time.time() for root,dirs,filenames in os.walk(path): for file in filenames: i=i+1 if re.search(keywords,file): j=j+1 filef=os.path.join(root,file) print(filef) results.append(filef) time_end=time.time() time_used=time_end-time_start print("符合的文件 : ",j) print("共扫描文件 : ",i) print("花费时间 : ",time_used) return results def FileSearchEx(self): keywords=input("the keywords : ") path=input("target dir : ") destination=input("the results : ") print("searching...") results=[] i=0 j=0 time_start=time.time() for root,dirs,filenames in os.walk(path): for file in filenames: i=i+1 if re.search(keywords,file): j=j+1 filef=os.path.join(root,file) results.append(filef) time_end=time.time() time_used=time_end-time_start fh=open(destination,"w+") for t in results: fh.write("\n"+t) fh.write("\n符合的文件 : "+str(j)) fh.write("\n共扫描文件 : "+str(i)) fh.write("\n花费时间 : "+str(time_used)) fh.close() os.system(destination) return results #www.iplaypy.comif __name__=="__main__": yz=brid() yz.FileSearchEx()
编橙之家文章,
相关内容
- Python字典方法查询数据示例,python字典,Python学习到py
- python解析读取ip区域信息,python解析ip区域,如下代码使
- Python抓取关键词代码片段,,用python来做数据抓
- python正则过滤文件指定邮箱地址的方法,python邮箱地址
- python实现whois查询功能的方法,python实现whois查询,今天
- Base64码转换的python实现源码,base64python,为了方便测试时
- 用scp备份openstack的instance镜像方法,scpopenstack,以下pyt
- Python xlrd方法实现excel数据查找提取保存操作,pythonxl
- web.py能条件判断的页面执行计时方法,web.py计时,编橙之
- Blowfish加密解密的Python实现方法,blowfishpython,Blowfish加密
评论关闭