Answers for "python list all txt files in directory"

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
0

get a list of all files python

import os
lst=os.listdir(directory)
Posted by: Guest on June-30-2021
-1

python search all txts in a folder

index_file =  open('index.txt', 'r')
    for line in index_file:
       ....
Posted by: Guest on December-12-2020

Code answers related to "python list all txt files in directory"

Python Answers by Framework

Browse Popular Code Answers by Language