471,355 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

Repository - file scanner

Greetings,

Could someone point my muddled head at a/the python repository. I know
that one exists but cannot find it again. In particular I am looking
for a standalone search tool that given a path searches files for a
text string.
Thanks,

jvh

Jun 8 '07 #1
11 1628
On Jun 8, 2:33 pm, HMS Surprise <j...@datavoiceint.comwrote:
Greetings,

Could someone point my muddled head at a/the python repository. I know
that one exists but cannot find it again. In particular I am looking
for a standalone search tool that given a path searches files for a
text string.

Thanks,

jvh
Are you looking for

A.) a Python script to search for file names that match a given text
string?
B.) a script to search for a given text string within a text file?
C.) a Python repository, as in the SVN/CVS area?

Here's a couple scripts for finding files given a path:

http://aspn.activestate.com/ASPN/Coo...n/Recipe/52224
http://aspn.activestate.com/ASPN/Coo.../Recipe/189973

And here's an interesting article on creating a Python "Find" utility:
http://www.python.org/search/hyperma...94q2/0116.html

This link has a chapter from "Learning Python" by O'Reilly that talks
about looking for words within files:
http://www.oreilly.com/catalog/lpyth...pter/ch09.html

The "repository" is here: http://svn.python.org/

Enjoy!

Mike

Jun 9 '07 #2
On Jun 8, 2:33 pm, HMS Surprise <j...@datavoiceint.comwrote:
Greetings,

Could someone point my muddled head at a/the python repository. I know
that one exists but cannot find it again. In particular I am looking
for a standalone search tool that given a path searches files for a
text string.

Thanks,

jvh
Search for text in a file, from O'Reilly's "Learning Python" book:
http://www.oreilly.com/catalog/lpyth...pter/ch09.html

Search for files given a path (or paths) and some text to search for:
http://aspn.activestate.com/ASPN/Coo...n/Recipe/52224
http://aspn.activestate.com/ASPN/Coo.../Recipe/189973
http://www.python.org/search/hyperma...94q2/0116.html

The Python repository (I think): http://svn.python.org/

Mike

Jun 9 '07 #3
En Sat, 09 Jun 2007 12:30:49 -0300, <ky******@gmail.comescribió:
On Jun 8, 2:33 pm, HMS Surprise <j...@datavoiceint.comwrote:
>Could someone point my muddled head at a/the python repository. I know
that one exists but cannot find it again. In particular I am looking
for a standalone search tool that given a path searches files for a
text string.

Are you looking for

A.) a Python script to search for file names that match a given text
string?
B.) a script to search for a given text string within a text file?
C.) a Python repository, as in the SVN/CVS area?
D.) The Python Package Index perhaps? http://www.python.org/pypi

--
Gabriel Genellina

Jun 9 '07 #4
On Jun 9, 12:38 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sat, 09 Jun 2007 12:30:49 -0300, <kyoso...@gmail.comescribió:
On Jun 8, 2:33 pm, HMS Surprise <j...@datavoiceint.comwrote:
Could someone point my muddled head at a/the python repository. I know
that one exists but cannot find it again. In particular I am looking
for a standalone search tool that given a path searches files for a
text string.
Are you looking for
A.) a Python script to search for file names that match a given text
string?
B.) a script to search for a given text string within a text file?
C.) a Python repository, as in the SVN/CVS area?

D.) The Python Package Index perhaps?http://www.python.org/pypi

--
Gabriel Genellina
Sorry about the dual post...google groups was acting very weird for me
yesterday.

Mike

Jun 10 '07 #5
On Jun 9, 5:33 am, HMS Surprise <j...@datavoiceint.comwrote:
Greetings,

Could someone point my muddled head at a/the python repository. I know
that one exists but cannot find it again. In particular I am looking
for a standalone search tool that given a path searches files for a
text string.
Why not use grep?

Jun 10 '07 #6
>
Why not use grep?
With Windows XP?

jh

Jun 11 '07 #7
On 6 9 , 3 33 , HMS Surprise <j...@datavoiceint.comwrote:
Greetings,

Could someone point my muddled head at a/the python repository. I know
that one exists but cannot find it again. In particular I am looking
for a standalone search tool that given a path searches files for a
text string.

Thanks,

jvh
grep maybe the best choice.
if you want a pure python script
here it is.

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# File: grep.py
# Author: phus

try:
import psyco
psyco.full()
except ImportError:
print 'no mod psyco'

import os, re

def grep_r(rx, path):
root = path
dirstack = [root]
while len(dirstack) 0:
dir = dirstack.pop()
try:
dirs = os.listdir(dir)
except:
print "os.listdir('%s') error: %s" % (dir, os.error)
continue
for name in dirs:
fullname = os.path.join(dir, name)
if os.path.isdir(fullname):
dirstack.append(fullname)
else:
grep(rx, fullname)

def grep(rx, file):
try:
f = open(file, "r")
for line in f:
if rx.findall(line):
print file, ":", line.strip()
f.close()
except:
print "grep error in %s" % file

if __name__ == "__main__":
patern = "blah blah"
rx = re.compile(patern, re.I)
grep_r(rx, '.')

Jun 11 '07 #8


Thank you all.

jh

Jun 11 '07 #9
HMS Surprise <jo**@datavoiceint.comwrites:
>>
Why not use grep?

With Windows XP?
www.cygwin.com

Jun 11 '07 #10
On Jun 12, 4:46 am, Paul Rudin <paul.nos...@rudin.co.ukwrote:
HMS Surprise <j...@datavoiceint.comwrites:
Why not use grep?
With Windows XP?

www.cygwin.com
Using cygwin for this problem is like using a sledgehammer to crack a
nut.

See http://gnuwin32.sourceforge.net/summary.html
*Lots* of goodies there.

HTH,
John

Jun 11 '07 #11
En Mon, 11 Jun 2007 15:46:51 -0300, Paul Rudin <pa*********@rudin.co.uk>
escribió:
HMS Surprise <jo**@datavoiceint.comwrites:
>>>
Why not use grep?

With Windows XP?

www.cygwin.com
Why? Try findstr /? at the command prompt.

--
Gabriel Genellina

Jun 11 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.