Your glob isn’t correct. You should add a /*
to the end of your path to select all files (or directories) in your path, and then check if they are files with os.path.isfile
. Something like:
from os.path import isfile
files=filter(isfile,glob.glob('%s/*'%path))
You also have an issue with the actual opening. When your with
statement ends, the file is closed and f
is no longer accessible. Anything you do with the file should be under the with
statement. And you shouldn’t explicitly close it.
2
solved How to read multiple txt file from a single folder in Python? [duplicate]