I'm trying to find files in a directory that have a certain extension. My code looks like this.
extensions = ('.txt')
for subdir, dirs, files in os.walk(rootdir):
for file in files:
ext = os.path.splitext(file)[-1].lower()
print(ext)
if ext in extensions:
print('.txt found')
The code almost always works fine. However, if the file does not have an extension it somehow returns .txt found.