search files in a directory
Hello, I need to open every file in a directory and search for a string. What module is needed to do this and how would I go about searching each file? -- http://mail.python.org/mailman/listinfo/python-list
Re: search files in a directory
david brochu jr wrote: > Hello, > > I need to open every file in a directory and search for a string. What > module is needed to do this and how would I go about searching each file? os.listdir(dir) gives a list of all the file in a directory. You can then loop through the list. open can be used to open a file The open file has several methods to read bytes from the file: read() gets the whole file at once readline() return a line at a time other possibilities exist You can test to see if a string s is in another string t with if s in t: ... Hope that helps, Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: search files in a directory
Gary Herron wrote: > david brochu jr wrote: > >> Hello, >> >> I need to open every file in a directory and search for a string. What >> module is needed to do this and how would I go about searching each file? [bash] find /path/to/dir -exec grep -le "searched string" {} \; Ho, you meant : doing this in Python ?-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list