Python写一个目录检索器

前言:

昨天看了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()

测试如下:

 

posted on 2018-06-23 20:57  东京$  阅读(285)  评论(0编辑  收藏  举报

导航