os.path.exists does not do pattern matching like that. Take a look at
the glob module.
--
regards,
kushal
In [4]: files = [f for f in os.listdir(os.getcwd()) if
os.path.splitext(f)[-1]=='.txt']
In [5]: files
Out[5]:
['pip-log.txt',
'extended_abstract.txt',
'testlog.txt',
'pymazon_error_log.txt',
'hny.txt']
from glob import glob
mylist = glob( "*.txt" )
for item in mylist:
print item
glob.glob returns a list of filenames. You need to loop over it and
pass individual elements to the open function.
for item in glob.glob('*.txt'):
# item is a filename. pass it to open and process however you need
I don't know how the set_text method works, but it sounds like it
might not work right if you call it repeatedly with different
filenames.
--
regards,
kushal
glob() returns a list of matching files, not a string. So you
need to iterate over those files:
filenames = glob.glob('*.*.txt')
if filenames:
for filename in filenames:
do_something_text(filename)
else:
for filename in glob('*.*.html'):
do_something_html(filename)
-tkc