Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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)

Source by www.alixaprodev.com #
 
PREVIOUS NEXT
Tagged: #find #html #files #current #directory #regular #expression #python
ADD COMMENT
Topic
Name
8+1 =