Python looks for an instance of a file in the directory with the specified extension
- 2020-04-02 14:46:40
- OfStack
This article is an example of how python looks up files in a directory with a specified extension. Share with you for your reference. The details are as follows:
Here you use python to find the file in the current directory with the extension.txt
import os
items = os.listdir(".")
newlist = []
for names in items:
if names.endswith(".txt"):
newlist.append(names)
print newlist
I hope this article has helped you with your Python programming.