Looking for a way to recursively search a repository for all files containing a multi line string and return the file names that contain it. The paragraph is just a header approx 30 lines.
Below is the approach I am taking but is not working.
repo = os.getcwd()
header = """ /*
/* .......paragraph
/* ..............
*/
"""
for file in glob.glob(repo):
with open(file) as f:
contents = f.read()
if header in contents:
print file
I am getting this error:
IOError: [Errno 21] Is a directory: '/home/test/python/repos/projects/one'
Edited new version @zondo
def findAllFiles(directory):
gen = os.walk(directory)
next(gen)
return [os.path.join(path, f) for path, _, files in gen for f in files]
def main():
print "Searching directory for copyright header"
for file in findAllFiles(repo):
with open(file) as f:
contents = f.read()
if header in contents:
print file