Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import os
  5.  
  6. try:
  7. dirname = sys.argv[1]
  8. search_string = sys.argv[2]
  9. except IndexError:
  10. exit('error: please provide a directory name and a search string')
  11.  
  12. try:
  13. files = os.listdir(dirname)
  14. except IOError:
  15. exit('error: directory does not exist or is not readable')
  16.  
  17. line_count = 0
  18.  
  19. for filename in files:
  20. full_path = os.path.join(dirname, search_string)
  21. for file in files:
  22. file = open(file).readlines()
  23. if search_string in file:
  24. print search_string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement