import os
import glob
for root, dirs, files in os.walk('F:\\workspace'):
for txtfile in glob.iglob(os.path.join(root,'*.txt')):
print txtfile
I can get the files with no “[]”,and it can work if the folder name have only one of the symbols,”[” or “]”.
I think I am using glob.iglob in the wrong way; but I don’t know how to get the files I need without it.
Thanks for your reply.
The Python documentation for
globmentions that it usesfnmatch.fnmatch()behind the scenes.If you only want to match against the file name but not the folder name, try the following code: