Reputation: 15
I am trying to modify below piece of code to search recursively for *.txt
files from current directory (directory in which I run my script) down.
for file in glob.glob('./*.txt'):
Any advice will be much appreciated.
Upvotes: 1
Views: 615
Reputation: 2182
You will be better off using os.walk rather than glob. It is designed for walking through directories like this. Try this code to get started:
import os
myfiles =[]
for root, dirnames, filenames in os.walk("./"):
for filename in filenames:
if(filename.endswith(".txt")):
myfiles.append("%s/%s" % (root, filename))
print myfiles
Upvotes: 1