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

Python写一个目录检索器

时间:2018-06-23 22:53:44      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:xpl   路径   format   .so   enc   com   readline   os.path   lse   

前言:

昨天看了Demon哥发的干货,有了次篇博文

干货链接:

 
 
 
正文:
1.将路径保存到一个txt,遍历
2.判断是否存在
3.存在则写入一个文件
代码:
import os
import optparse
payload=open(mulu.txt,r)
def main():
    parser=optparse.OptionParser()
    parser.add_option(-x,dest=jiansuo,action=store_true,help=Retrieval path)
    (options,args)=parser.parse_args()
    if options.jiansuo:
        jiancha()
    else:
        parser.print_help()
        exit()

def jiancha():
    for p in payload.readlines():
        jiance=os.path.exists({}.format(p.strip()))
        if jiance==True:
            print([>>>]The path of existence:{}.format(p))
            lk=open(word.txt,w)
            lk.write(p)
            lk.close()
        else:
            print([x]A path that does not exist:{}.format(p))

if __name__ == __main__:
    main()

测试如下:

技术分享图片

 

Python写一个目录检索器

标签:xpl   路径   format   .so   enc   com   readline   os.path   lse   

原文地址:https://www.cnblogs.com/haq5201314/p/9218852.html

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