Created
September 26, 2014 18:35
-
-
Save yousefamar/1cee7d894de5bb1a95ed to your computer and use it in GitHub Desktop.
A old python script that walks a directory and searches files for a specified term
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
sTerm = raw_input("Search term: ") | |
for root, dirs, files in os.walk("."): | |
print root | |
for fname in files: | |
print " "+fname | |
with open(root+os.sep+fname) as f: | |
flines = f.readlines() | |
for i,line in enumerate(flines): | |
if sTerm in line: | |
print " "+"Line "+str((i+1))+": "+line | |
print "" | |
raw_input("Press enter to quit...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment