Gossamer Forum
Home : General : Perl Programming :

binary file search :)

Quote Reply
binary file search :)
Good morning all!
I've posted this a few weeks ago, but no one answered, so I do it again.
There're many scripts, that will search for a string/word/number in any text files in all directories... But I am looking for a script that will for a file name. For example:
let's say I got a /arc/files/binary/games/doom1.zip file, and at the same time I got hundereds of other game shareware of any other binary files. Now I need to give the user a chance to search for a specific file. Something like "Start/Find/Files or Folders" in Windows 9.x

Hope to get a reply from some one, who've seen this kind'a script...
Thank you in advance.

Pasha

------------------

-[ It's just another night; good morning Webmasters! ]-
Quote Reply
Re: binary file search :) In reply to
Basically, this sounds like trying to interface a UNIX find feature through a Perl Interface/CGI. Its not too difficult to do, but to be honest, but you'd be better off to use the Perl File::Find module that takes care of some of the underlying OS problems. I suggest reading the information on this module, as it uses some items in Perl that may need detailed explaination if you are not familiar with them.

Let me know if you need a more detailed explaination.

------------------
Fred Hirsch
Web Consultant & Programmer
Quote Reply
Re: binary file search :) In reply to
Please do explain.

------------------

-[ It's just another night; good morning Webmasters! ]-
Quote Reply
Re: binary file search :) In reply to
Something like this should do the trick:

Code:
#!/usr/bin/perl -w
# ------------------------------------------
use strict;
use CGI;
use File::Find;

my $in = new CGI;
my $file = $in->param('find');
my $base_dir = '/path/to/root';
print $in->header();
print "Finding file ... <br><br>\n";
print "No files specified." and exit if (!$file);
print "Bad file: $file." and exit unless ($file =~ /^[\w\d\.\_\-]+$/);
&find ( sub { /$file/io and print "$File::Find::name<br>\n" }, $base_dir);
print "Done";
# ------------------------------------------

It takes as input a form field 'find', and then prints out all the files it finds in the base directory.

Hope this helps,

Alex
Quote Reply
Re: binary file search :) In reply to
Thanks Alex,
I'll try this code.

BTW: what's a <form> code for this script?

Pasha


[This message has been edited by Pasha (edited February 08, 1999).]
Quote Reply
Re: binary file search :) In reply to
 
Quote:
my $base_dir = '/';

That will search your entire hard drive, which can take quite a long time! If the files are only in your ftp dir, you might want to try:

$base_dir = '/home/ftp';

or whatever it is. If you really need to search your whole hard drive (which i'm 99% sure you don't), then you will need a real search engine that will index things first. Take a look at cgi-resources for one..

Cheers,

Alex
Quote Reply
Re: binary file search :) In reply to
For some reason it either doesn't finds file or doesn't prints the output.

See it working at http://find.virtualave.net/cgi-bin/find.htm
http://find.virtualave.net/cgi-bin/find.cgi

This is "find.cgi" file:
========================

#!/usr/bin/perl -w
# ------------------------------------------
use strict;
use CGI;
use File::Find;
my $in = new CGI;
my $file = $in->param('find');
my $base_dir = '/';
print $in->header();
print "Finding file ... <br><br>\n";
print "No files specified." and exit if (!$file);
print "Bad file: $file." and exit unless ($file =~ /^[\w\d\.\_\-]+$/);
&find ( sub { /$file/io and print "$File::Find::name<br>\n" }, $base_dir);
print "Done";
# ------------------------------------------


And this is "find.htm" file:
============================

<html>
<body>
<form action="/cgi-bin/find.cgi" method="GET">
<input type="TEXT" name="find" size="30"> <input type="Submit" value="Find file">
</form>
</body>
</html>

For some reason the process is taking a very long time...
Any ideas, Alex? What am I doing wrong?

Pasha

------------------

-[ It's just another night; good morning Webmasters! ]-
Quote Reply
Re: binary file search :) In reply to
Alex,
I've been looking for it, as you advised. But my search has failed Smile in another words, I didn't find anything useful and/or similar to what I have problams with.
There must be the way to do this. I mean, I'm fine with this script taking long time, but the main problem is that this script doesn't show me the results, even if I've serched for the files that I have in my directory, like "background.gif", "gossamer.gif", "index.htm".
It just says that the search is "done", and nothing more.
Sure, I could rewrite this script on my own, but I don't know the Perl as well as other people (like you or Bobsie) on this BBS, I just started to learn Perl a few weeks ago... Smile
Well anyway guys, if any one could suggest an idea, then please do. There's a similar example of this kind of search at http://www.shareware.com but I think that they have a database file, which they search by keywords. If so, then there's gonna be no problem, the only thing I might need to find out how to "spider" my website to get all files listed.

Conclusion:
"File Search" is a good thing to have, if you know how the hell it should be written. Wink

Thank you in advance.

Pasha

------------------
-[ It's just another night; good morning Webmasters! ]-
Quote Reply
Re: binary file search :) In reply to
Guys, I've found a simple script at
http://www.cusd.claremont.edu/~ccross/cgi.html
that user can use to search the database, modified it a little, and now everything works! Smile
http://find.virtualave.net/00/index.htm

Well, not everything actually. I still have to figure out how to "spider" my website for files. Again, I spend hours looking for it, but no luck so far.
Just hope any one here knows the code.

Pasha



[This message has been edited by Pasha (edited February 10, 1999).]