Answers for "read all the 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
12

get files in directory python

import os
files_and_directories = os.listdir("path/to/directory")
Posted by: Guest on June-12-2020
7

list files in directory python

import os
print(os.listdir('/path/to/folder/to/list'))
Posted by: Guest on April-22-2020
6

python list all files in directory

from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
Posted by: Guest on April-04-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
1

python list all files in directory

import os
 arr = os.listdir()
 print(arr)
 
 >>> ['$RECYCLE.BIN', 'work.txt', '3ebooks.txt', 'documents']
Posted by: Guest on April-15-2021

Code answers related to "read all the files in a folder python"

Python Answers by Framework

Browse Popular Code Answers by Language