On Sep 25, 11:39 am, Shriphani <[EMAIL PROTECTED]> wrote: > If I have a string "fstab", and I want to list out the files in whose names > the word fstab appears should I go about like this : > > def listAllbackups(file): > list_of_files = os.listdir("/home/shriphani/backupdir") > for element in list_of_files: > if element.find(file) != -1: > date = ### > time = #### > return (date, time)
I would do something like this instead: >>> for root, dirs, files in os.walk('.'): ... for f in files: ... if 'text' in f: ... print f ... gimp-text-tool gimp-text-tool.presets text.py~ textwrap.pyc textwrap.py ... You can append the output to a list and return that list if you want to encapsulate this in a function. -- http://mail.python.org/mailman/listinfo/python-list