Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

How to get a file listing

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


coetzee.evert at gmail

Feb 18, 2010, 11:46 AM

Post #1 of 13 (1331 views)
Permalink
How to get a file listing

Hi guys

I wanted to do a simple script to show all pictures in a specific folder.
But I don't see any functions to read all files in a folder.

The logic needs to go something like this:
- Open directory to read file list
- If file like *.gif then print filename

Any tips?
--
View this message in context: http://old.nabble.com/How-to-get-a-file-listing-tp27644565p27644565.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


mcapone at cablewholesale

Feb 18, 2010, 11:51 AM

Post #2 of 13 (1301 views)
Permalink
Re: How to get a file listing [In reply to]

#!/usr/local/bin/perl

chdir("/path/to/my/directory");

while($filename=<*.gif>)
{
print "$filename\n";
}

# Enjoy!


ceauke wrote:
> Hi guys
>
> I wanted to do a simple script to show all pictures in a specific folder.
> But I don't see any functions to read all files in a folder.
>
> The logic needs to go something like this:
> - Open directory to read file list
> - If file like *.gif then print filename
>
> Any tips?
>


coetzee.evert at gmail

Feb 18, 2010, 12:03 PM

Post #3 of 13 (1300 views)
Permalink
Re: How to get a file listing [In reply to]

Sorry, I completely forgot to say.

This is for MOD_PERL on apache. So I want the webserver to show an unknown
amount of pictures.
--
View this message in context: http://old.nabble.com/How-to-get-a-file-listing-tp27644565p27644823.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


dzuy at infinity-studios

Feb 18, 2010, 12:12 PM

Post #4 of 13 (1299 views)
Permalink
Re: How to get a file listing [In reply to]

opendir(DIR, "/your/dir");
my @gifs = grep { /\.gif$/ } readdir(DIR);

ceauke wrote:
> Hi guys
>
> I wanted to do a simple script to show all pictures in a specific folder.
> But I don't see any functions to read all files in a folder.
>
> The logic needs to go something like this:
> - Open directory to read file list
> - If file like *.gif then print filename
>
> Any tips?
>


coetzee.evert at gmail

Feb 18, 2010, 12:20 PM

Post #5 of 13 (1299 views)
Permalink
Re: How to get a file listing [In reply to]

Wow, thanks. It's working. I have a problem with the dir structure:
Perls seems to search for mydir in \cgi-bin\ and not where I defined mydir
in the apache conf file.

So my structure is like this:
\cgi-bin\myprog.cgi <---- my program
\cgi-bin\mydir1\ <----- this one can be seen by my program
\mydir2\ <----- how do I show this content?
--
View this message in context: http://old.nabble.com/How-to-get-a-file-listing-tp27644565p27645041.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


alansyoungiii at gmail

Feb 18, 2010, 12:26 PM

Post #6 of 13 (1296 views)
Permalink
Re: How to get a file listing [In reply to]

On Thu, Feb 18, 2010 at 13:20, ceauke <coetzee.evert [at] gmail> wrote:
> So my structure is like this:
> \cgi-bin\myprog.cgi   <---- my program
> \cgi-bin\mydir1\   <----- this one can be seen by my program
> \mydir2\    <----- how do I show this content?

opendir my $DH, '\mydir2\' or die "Unable to open mydir2: $!";

The rest as before.
--
Alan


mcapone at cablewholesale

Feb 18, 2010, 12:31 PM

Post #7 of 13 (1293 views)
Permalink
Re: How to get a file listing [In reply to]

Depending on your server setup, you may or may not be able to read
\mydir2\. Whether on windows or a unix variant, apache is configured to
run as "some user" (often, "nobody" on unix); and that user needs to be
given at least read access to the \mydir2\ directory in order for this
to work.

Alan young's snippet he gave you:

opendir my $DH, '\mydir2\' or die "Unable to open mydir2: $!";

should quickly tell you if you don't have read permission on \mydir2.




ceauke wrote:
> Wow, thanks. It's working. I have a problem with the dir structure:
> Perls seems to search for mydir in \cgi-bin\ and not where I defined mydir
> in the apache conf file.
>
> So my structure is like this:
> \cgi-bin\myprog.cgi <---- my program
> \cgi-bin\mydir1\ <----- this one can be seen by my program
> \mydir2\ <----- how do I show this content?
>


coetzee.evert at gmail

Feb 18, 2010, 12:39 PM

Post #8 of 13 (1295 views)
Permalink
Re: How to get a file listing [In reply to]

Hi guys

Running apache on winxp.
The bizarre thing is in my browser I can put:

myserver.com/mydir2/test.gif and that works
myserver.com/cgi-bin/mydir/test.gif gives internal server error. but I know
the opendir command can at least read mydir. Still, how should I 'enable'
mydir2?

another issue is that even if I put xxx as the dir to open, I never get the
die text?

--
View this message in context: http://old.nabble.com/How-to-get-a-file-listing-tp27644565p27645284.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


k.ghadami at ibson

Feb 19, 2010, 1:33 AM

Post #9 of 13 (1287 views)
Permalink
Re: How to get a file listing [In reply to]

Hi i asume you using xamp and test.gif is a simple git picture?

The apache webserver will try to execute

myserver.com/cgi-bin/mydir/test.gif

put the picture anywhere else (eg C:\xampp\htdocs\mydir\).
Maybe there are some more infos in your log file (eg.
C:\xampp\apache\logs\error.log)

You can configure the directories and there behavior in
C:\xampp\apache\conf\httpd.conf.

best regards


> Hi guys
>
> Running apache on winxp.
> The bizarre thing is in my browser I can put:
>
> myserver.com/mydir2/test.gif and that works
> myserver.com/cgi-bin/mydir/test.gif gives internal server error. but I know
> the opendir command can at least read mydir. Still, how should I 'enable'
> mydir2?
>
> another issue is that even if I put xxx as the dir to open, I never get the
> die text?
>
>


coetzee.evert at gmail

Feb 20, 2010, 10:01 AM

Post #10 of 13 (1274 views)
Permalink
Re: How to get a file listing [In reply to]

Hi there

Here is my code. I get the IMG displayed but also the perl error: No such
file or directory.

"
#!E:\ea12\apps\tech_st\10.1.2\perl\5.6.1\bin\MSWin32-x86\perl.exe
print "Content-type: text/html \n\n";

print "Test:";
print " /Ski/temp.jpg ";

opendir(DIR, "/Ski") or die print "Error $!";

print "Dir list: ";
while( ($filename = readdir(DIR))){
print("$filename");
}
closedir DIR; "

It seems like the webserver (apache) knows what /Ski is but perl doesn't.
It's looking for /ski in cgi-bin. my /ski folder is out of the root. I have
an alias, directory and location defined in httpd.conf for it. How do I get
perl to see it?
--
View this message in context: http://old.nabble.com/How-to-get-a-file-listing-tp27644565p27668252.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


bvs7085 at gmail

Feb 20, 2010, 10:07 AM

Post #11 of 13 (1272 views)
Permalink
Re: How to get a file listing [In reply to]

Apache knows the context, PERL does not.

Fully qualify that directory name and it should work.





On 2/20/2010 1:01 PM, ceauke wrote:
> Hi there
>
> Here is my code. I get the IMG displayed but also the perl error: No such
> file or directory.
>
> "
> #!E:\ea12\apps\tech_st\10.1.2\perl\5.6.1\bin\MSWin32-x86\perl.exe
> print "Content-type: text/html \n\n";
>
> print "Test:";
> print " /Ski/temp.jpg ";
>
> opendir(DIR, "/Ski") or die print "Error $!";
>
> print "Dir list: ";
> while( ($filename = readdir(DIR))){
> print("$filename");
> }
> closedir DIR; "
>
> It seems like the webserver (apache) knows what /Ski is but perl doesn't.
> It's looking for /ski in cgi-bin. my /ski folder is out of the root. I have
> an alias, directory and location defined in httpd.conf for it. How do I get
> perl to see it?
>


coetzee.evert at gmail

Feb 20, 2010, 10:16 AM

Post #12 of 13 (1271 views)
Permalink
Re: How to get a file listing [In reply to]

No,
that doesn't work either. I used opendir (DIR, "G:\FTP\Ski") ...
I've tried the slashes in all directions, and with and without preceding and
slashes in the end.
e.g. \Ski, \Ski\, /ski, /ski/

How do I get perl to understand the context? is there some function that
points to the root? (even that will be pointless as I'm on WINXP where I
have multiple drives.



Apache knows the context, PERL does not.

Fully qualify that directory name and it should work.

--
View this message in context: http://old.nabble.com/How-to-get-a-file-listing-tp27644565p27668907.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


coetzee.evert at gmail

Feb 20, 2010, 10:18 AM

Post #13 of 13 (1273 views)
Permalink
Re: How to get a file listing [In reply to]

Sorry,

got it working with your advice:
opendir(DIR, "G:/FTP/Ski") or die print "Error $!"; worked in the end...
Damn these slashes :-D

Thanks for the help
--
View this message in context: http://old.nabble.com/How-to-get-a-file-listing-tp27644565p27668922.html
Sent from the mod_perl - General mailing list archive at Nabble.com.

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.