Below you can find a simple script to search text in files. I'm looking for how to be more crossplatform i mean how to avoid '\' in path to look through all dirs and do it with standard library from Python. Because as i know, mac use '/' instead of backslash. Any idea how to do it?
#!/usr/bin/env python
def find(text, search_path):
res = []
for subdir, dirs, files in os.walk(search_path):
for fname in files:
if os.path.isfile(subdir + "\\" + fname):
with open(subdir + "\\" + fname) as f:
for i, line in enumerate(f):
if text in line:
res.append([fname, i])