473,326 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 1758
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: ValK | last post by:
Hi, Here is my problem. I need to check if scanner finished scanning the document. I'm using scanner interface that came with the scanner. I tried to open file and catch IO Exception for "The...
7
by: DemonWasp | last post by:
I've been having some trouble getting the Scanner class to operate the way I'd like. I'm doing some fairly basic file IO and I can't seem to get the class to load the last line/token any way I try....
4
Ispep
by: Ispep | last post by:
Hi, unfortunately having a bit of difficulty with a question from an Open University course I'm currently doing. If you could help me out in any way I'd be grafeul (though obviously it goes without...
0
by: Filemaxor | last post by:
I have gotten my code to be able to allow people to add new text to a .txt document and able to call up files so the user can see whats in it. The problem i'm having is getting the for loop to work...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.