Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file::find not working

Status
Not open for further replies.

ibjdt

Programmer
Nov 25, 2002
63
i want to allow users to search documents file names via cgi script.
i found some code and modified per below.
the script hasn't worked and doesn't appear to actually be accessing the directory.
i added a counter and several other print statements to track progress. it only goes through one loop (output shown below script). in fact, in its current state i ask the script to print the filename to screen - i get a blank line.

how can i determine if it's accessing the dir??

please help.

thanks.



Code:
use File::Find;
my $q = new CGI;
print $q->header;
my $query = $q->param("query");
print "\n<p>For the query $query, these results were found:</p>\n<ol>\n";
undef $/;

find(&findit, "/data");

sub findit
{
print "$File::Find::name<br><br>";
 return if($_ =~ /^\./);
 stat $File::Find::name;
 return if -d;
# return unless -r;
$count++;
print "$count<br><br>";

# return unless (/$query/i);
print "$File::Find::dir";
 print "<li>hello<a href=\"$File::Find::name\">$File::Find::name</a></li>\n";
print "done1";
}



print "</ol>\n";

print "done";
exit;



Code:
OUTPUT
===========
For the query t, these results were found:

***filename should be here***

1


hello done1
done

 
i do have permission to the folders i am trying to access.

i can't even get info from the cgi-bin from which i am running the script.

???

thanks.
 
You are not calling your subroutine properly. It has to be called as a reference rather than called directly. Change this:

find(&findit, "/data");

to this:

find(\&findit, "/data");
 
thanks for the help.
i have it working (bottom), but i have run into two other issues.
(i could probably use some help on my 'header' info - i just kept trying stuff until it worked.)

issue 1
this is on my intranet site (network drive w:/ accessed via i got it to work for any folder on the 'w' drive, but ultimately i need it to search a non-intranet document storage drive (network drive g:/) - same network - 2 levels up.

in other scripts i have used

Code:
\\drivename\mainfolder\docstore

to point/link to non-intranet files with no problem, but it doesn't work here. i have tried literal '\'

Code:
find(\&findit, "\\drivename\mainfolder\docstore");

and escaped '\'

Code:
find(\&findit, "\\\\drivename\\mainfolder\\docstore");

but no results come up.

issue 2
where i create the link

Code:
href=\"$File::Find::name\"

i toyed with

Code:
href=\"[URL unfurl="true"]http://address/$File::Find::name\"[/URL]

to make the file available to right click/save as.
if i don't add the it won't download. this worked well for results from the cgi-bin folder or below,
but to access a folder outside cgi-bin i used ./foldername as the dir. this screws up the link path. it creates it as

Code:
[URL unfurl="true"]http://address./filename[/URL]

any ideas?? i'm lost.
thanks.


Code:
#!/usr/bin/perl -w

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use File::Find;
my $q = new CGI;
print $q->header;
my $query = $q->param("query");
print "\n<p>For the query <b><u>$query</u></b>, these results were found:</p>\n<ol>\n";
undef $/;

find(\&findit, "cgi-bin/data");

sub findit
{
 return if($_ =~ /^\./);
 stat $File::Find::name;
 return if -d;
 return unless -r;

 return unless (/$query/i);
 print "<li><a href=\"$File::Find::name\">$File::Find::name</a></li>\n";
}



print "</ol>\n";
exit;
 
Use forward slashes for the drive path instead of back.

//drivename/folder/file


As far as downloading outside of cgi-bin, any good webserver would not allow that due to security reasons. Perhaps write your script to copy the file from the external location into a temporary file in cgi. Once the file is downloaded, delete it. Perhaps there is another way, but I am not aware of it.
 
i am on a windows platform with activestate perl 5.8.
this is the same system i have used for all my scripting.

i have other scripts which allow 'g' drive links to be created from database info. in that scenario the db entries have time limits. if expired, the link points to the archived doc on the 'g' drive (g:\). my perl code for that is


Code:
<a href=\"\\\\drivename\\mainfolder\\doc storage\\nextlevel\\$searchdata[0].pdf\">$searchdata[0]</a>


when i view source, it looks like this


Code:
<a href="\\drivename\mainfolder\doc storage\nextlevel\docnumber.pdf">docnumber</a>


when i mouseover, the status bar shows


Code:
file://drivename/mainfolder/doc%20storage/nextlevel/docnumber.pdf


*notice the %20 auto inserted where there was a space previously.

i have verified that the old script (in the cgi-bin) allows right click - save as to a file that's not on the same drive as the intranet site, let alone in the same folder.

i went back to my search script and tried every possible combo of / and \ and escaped and ./ and ../.

something interesting..... i tried


Code:
my $dir = '\\\\drivename\\mainfolder\\Doc storage';

print "<A HREF=\"$dir\\monthly.xls\">monthly.xls</a>";

find(\&findit, $dir);


it didn't return search results, but the link showed up with syntax 'file://....' and allowed me to download from the 'g' drive.

????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top