Answers for "how to open and read all files in a folder python"

3

python open each file in directory

import os
for filename in os.listdir(os.getcwd()):
   with open(os.path.join(os.cwd(), filename), 'r') as f:
Posted by: Guest on July-03-2020
-2

python read all text files in directory

import os
from re import search

arr = os.listdir()
strtxt = ".txt"
for txtfile in arr:
    if txtfile.__contains__(strtxt):
        fileObject = open(txtfile, "r")
        data = fileObject.read()
        print(data)
Posted by: Guest on December-22-2020

Code answers related to "how to open and read all files in a folder python"

Python Answers by Framework

Browse Popular Code Answers by Language