Answers for "find all html files in a current directory using regular expression in python"

0

find all html files in a current directory using regular expression in python

import re
import os
currentdir = os.getcwd()
files = os.listdir(currentdir)
pattern = "^.*html$"
prog = re.compile(pattern)
htmlfiles=[]
for file in files:
    result = prog.findall(file)
    if len(result)!=0:
        htmlfiles.append(result[0])

for htmlfile in htmlfiles:
    print(htmlfile)
Posted by: Guest on April-19-2022

Code answers related to "find all html files in a current directory using regular expression in python"

Python Answers by Framework

Browse Popular Code Answers by Language