How do I open all files in a directory in python? -
this question has answer here:
- can't open files directory in python 1 answer
i have code
import os def load(): filename in os.listdir("directorypath"): content = open(filename, "r") load()
and know how load files filename
returns, @ moment error saying filenotfounderror: [errno 2] no such file or directory: 'adjectives.txt'
os.listdir()
returns filename, not full path. need pass whole path open
. can use os.path.join
combine directory , filename:
content = open(os.path.join('directorypath', filename), 'r')