newbie 'Find File' question.
G. Willoughby
thecalm at NOSPAM.btinternet.com
Fri Jul 27 14:00:20 EDT 2001
very useful ta, maybe you could help me with a little problem, my code:
def go():
status.set("Searching...")
if checkEntryField() == 1:
resultPane.delete(0, END) # Clear the results pane!
searchString=str(entryField.get()) # Get search string
def search(of, dir, files):
for file in files:
if file == searchString:
of.insert(END, os.path.join(dir, file))
driveList=string.split(win32api.GetLogicalDriveStrings(),'\0')[:-1] # Get
Drives
for x in range(0,len(driveList)):
os.path.walk(driveList[x], search, resultPane)
status.set("Done")
when this script is run i get this error:
Local name 'searchString' in 'go' shadows use of 'searchString' as global in
nested scope 'search' def go()
HUH!!!
any ideas, i'm learning as i go along :)
G. Willoughby
"Volucris" <volucris at hotmail.com> wrote in message
news:3b5f3d46$0$327$6e49188b at news.goldengate.net...
> Yeah that was one of the first scripts I ever wrote. It's under 20 lines,
so
> it's not documented. Just remember os.path.walk() if you friend. It will
> only scan the C: drive, but that would be easy to change. I think you need
> some platform API stuff (at least on Windows you do) to get the available
> drives. I can't remember what it is, though. Does anyone else? Hope this
> helps.
>
> ---Begin mpsscan.py---
>
> #mp3scan.py
> print 'MP3 Scan 0.1 (volucris at hotmail.com)\n\n'
> print 'This program will scan the C: drive for files ending in \'mp3\'.'
> print 'The results will be stored in \'C:\\mp3scan_results.txt\'.\n'
> res = raw_input('Press ENTER to begin.')
> if res != 'q':
> import os
> def test(of, dir, files):
> for file in files:
> if file[-3:] == 'mp3':
> of.write(os.path.join(dir, file) + '\n')
> f = open('c:\\mp3scan_results.txt', 'w')
> os.path.walk('c:\\', test, f)
> f.close()
> print '\nScan complete. Check \'C:\\mp3scan_results.txt\' for
> results.\n'
>
> res = raw_input('Press ENTER to quit.')
>
> ---End mp3scan.py---
>
> --
>
> Volucris (a) hotmail.com
> "Eu não falo uma única palavra do português."
>
> "G. Willoughby" <thecalm at NOSPAM.btinternet.com> wrote in message
> news:9jn5kb$k16$1 at neptunium.btinternet.com...
> > Has anybody coded a script to simulate the windows/mac find file
> utilitity?
> > i'm using this to help me learn Tkinter and Python. I have created the
GUI
> i
> > just need a few design tips for the search code. basically i need to
> search
> > all drives (not A:) for a file. any ideas? :) .
> >
> > G. WIlloughby.
> >
> >
>
>
More information about the Python-list
mailing list