[Tutor] Help search files

Alan Gauld alan.gauld at btinternet.com
Thu Jul 5 16:41:42 CEST 2007


"Alejandro Decchi" <adecchi at gmail.com> wrote

> Yes i am a newbie in web design but i understand the concept of CGI.

OK, I'll ignore that aspect for now.

> My problem is that I do not know how to do a search based in binary
> files.For example a user conect to my webpage and dicide to search
> windows.iso he write in the textbox and put submit and must appear 
> the
> result to download the link.

You said that you were searching the file name not the content
so it makes no difference if the file is text or binary. Use glob.glob
to get a list of files matching a pattern.

Or, use os.listdir to get all files and then manually compare each
filename to your input pattern.

Here is a very simple example using glob

#################
import glob

pattern = raw_input("What file name? ")

for filename in glob.glob(pattern):
    print filename, "matches", pattern
##################

Now, what still puzzles you?

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list