Read all files in the Directory python

Description

Python Program to read the contents of all the files located in the directory

Solution

from os import listdir
from os.path import isfile, join
files = [f for f in listdir("/home/administrator/files") if isfile(join("/home/administrator/files", f))]
for file in files:
    print(file)
    f=open(file,'r')
    print(f.read())
    print("\n\n End of File \n\n")
    
    

Explanation

Collect the files in the directory using listdir() method.
Using "for" open each file in read mode and read the content of file and close the file.