Skip to content

Instantly share code, notes, and snippets.

@rririanto
Created March 25, 2016 10:26
Show Gist options
  • Save rririanto/5dc790aac90e4656331d to your computer and use it in GitHub Desktop.
Save rririanto/5dc790aac90e4656331d to your computer and use it in GitHub Desktop.
Python Small Script to find text string in files
#!/usr/bin/env python
'''
@jimmyromanticde
Problem
Find or Search text string in files
'''
DIRFOLDER = '/home/romanticdevil/myworkspace/Dj1.4/project/newversion1.0/titik_tanya'
import os, re
text = raw_input('string search: ')
datas = []
for i, j, k in os.walk(DIRFOLDER):
for x in k:
try:
for data in open(i+'/'+x,'r').readlines():
if re.search(text, data):
datas.append(os.path.join(i, x))
except:
continue
datas = set(datas)
for i in datas:
print "Found on path: %s"%i
b = raw_input('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment