472,960 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 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 1734
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.