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()

测试如下:

猜你喜欢

转载自www.cnblogs.com/haq5201314/p/9218852.html