Help with perl glob(*) function

P

perlUSER

Hello all;
I am trying to write a perl script to list the files on our network
drive. First I used the glob on the local, c:\ drive and it worked
fine. Then I changed glob(c:/*.*) to glob(k:/*.*) and no files were
listed even though my network directory is not empyt.

Could someone please help me with this issue or please suggest an
alternative approach.

Regards,
Sri.
 
K

Kraven

perlUSER said:
Hello all;
I am trying to write a perl script to list the files on our network
drive. First I used the glob on the local, c:\ drive and it worked
fine. Then I changed glob(c:/*.*) to glob(k:/*.*) and no files were
listed even though my network directory is not empyt.

Could someone please help me with this issue or please suggest an
alternative approach.

Regards,
Sri.
try this

foreach (glob "k:/*.*") {
print $_,"\n";
}

or this

foreach (<k:/*.*>) {
print $_,"\n";
}
 
B

Brian McCauley

perlUSER said:
I am trying to write a perl script to list the files on our network
drive. First I used the glob on the local, c:\ drive and it worked
fine. Then I changed glob(c:/*.*) to glob(k:/*.*) and no files were
listed even though my network directory is not empyt.

Are you running the script as youself or as some other user?

If the latter does this other user have the drive mapped and do they
have permission to list the directory?
 
P

perlUSER

Kraven said:
try this

foreach (glob "k:/*.*") {
print $_,"\n";
}

or this

foreach (<k:/*.*>) {
print $_,"\n";
}

First of all thanks for taking my question. Your suggestion worked when
I executed my script in the console. However didn't display in my
perl-cgi script. Any thoughts?

Regards,
Sri.
 
A

A. Sinan Unur

First of all thanks for taking my question. Your suggestion worked when
I executed my script in the console. However didn't display in my
perl-cgi script. Any thoughts?

perldoc -q "My CGI script runs from the command line"

Sinan
 
K

Kraven

perlUSER said:
First of all thanks for taking my question. Your suggestion worked when
I executed my script in the console. However didn't display in my
perl-cgi script. Any thoughts?

Regards,
Sri.

Some example of what you have would help, but you could try...

use CGI qw(header start_html end_html);

print header('text/html');
print start_html('K Directory');
print "<h1 align=center>Welcome to the Directory of K:\\</h1>\n";
print "<hr width=70%>\n";

foreach $filename (glob "k:/*.*") {
print "$filename\n";
}


print "<br><br><center><a href=# onClick=window.close()>Close
Window</a></center><br>";

print end_html;


anyway, the above is untested, hope it works for you.
 
P

perlUSER

A. Sinan Unur said:
perldoc -q "My CGI script runs from the command line"

Sinan

Since I am using Optiperl, I guess I "can" run the script in console
mode.

Sri.
 
X

xhoster

perlUSER said:
Hello all;
I am trying to write a perl script to list the files on our network
drive. First I used the glob on the local, c:\ drive and it worked
fine. Then I changed glob(c:/*.*) to glob(k:/*.*) and no files were
listed even though my network directory is not empyt.

Is this FAQ relevant?

perldoc -q "\*.\*"
Why doesn't glob("*.*") get all the files?

Could someone please help me with this issue or please suggest an
alternative approach.

Check $! after the glob. It may be able to tell you something about why
glob is failing. At least on my machine it does:

perl -le 'print foreach glob "/does/not/exist/*"; print $!'
No such file or directory

perl -le 'print $_ foreach glob "/tmp/no_permissions/*"; print $!'
Permission denied


Xho
 
R

robic0

Hello all;
I am trying to write a perl script to list the files on our network
drive. First I used the glob on the local, c:\ drive and it worked
fine. Then I changed glob(c:/*.*) to glob(k:/*.*) and no files were
listed even though my network directory is not empyt.

Could someone please help me with this issue or please suggest an
alternative approach.

Regards,
Sri.

Sri, the bottom line is this:

Perl's 'glob' function is the buggiest thing since the
Ford Pinto. Its gassoline tank will catch fire when a rock hits it.
My advice to you is:
Instead of taking a bunch of 'try this', to face the threat head
on and ask when will the Perl gods fix the goddamed thing ???

Thats my advice...

Oh, btw, try using it in windows with, not only long names but with
spaces...

gluk
 
R

robic0

Sri, the bottom line is this:

Perl's 'glob' function is the buggiest thing since the
Ford Pinto. Its gassoline tank will catch fire when a rock hits it.
My advice to you is:
Instead of taking a bunch of 'try this', to face the threat head
on and ask when will the Perl gods fix the goddamed thing ???

Thats my advice...

Oh, btw, try using it in windows with, not only long names but with
spaces...

gluk

Oh, there seems to be an issue between single/double quotes.
Geez, why is that ?????

Robic0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top