查找文件夹内所有.js文件的路径

 # coding: utf-8
import os
import re

# 要找的文件路径
path = "./"
# 要找的文件后缀
suffix = "js"
# 路径列表
file_list = []
# URL列表
url_list = []

# 打开路径
files = os.listdir(path)

# 找全部文件的路径
for root, dirs, names in os.walk(pash):
    for filename in names:
        # 查找文件后缀
        if filename[-2:] == suffix :
            file = str(os.path.join(root, filename))
            file_list.append(file)

# 遍历路径获取文件里的URL
for file in file_list:
    with open(file, 'rb') as f:
        text = f.read()
        # re 匹配URL
        url_list = url_list + re.findall(r'bankend.endCustService \+ .*?,', text)

# 去重
url_list = list(set(url_list))
# 排序
url_list.sort()
# 写入txt
with open('./Url.txt', 'w') as f:
    for i in url_list:
        f.write(i + '\n')

你可能感兴趣的:(查找文件夹内所有.js文件的路径)