Recursive directory read with File::Find

K

kimanhtle

I would like to do a recursive read of a directory on my local
computer. Is this possible with File::Find? If not, is there any other
way to do it in Perl?
 
J

John W. Krahn

Thanks! Would you happen to have an example? I only got it to work for
a UNIX path not a path on my local computer. It could be I didn't
escape the path right. For example, if I have "C:\projects\docs
\HUNGER_AWARENESS_04212008", would I have to pass it as "C:\\projects\
\docs\\HUNGER_AWARENESS_04212008"?

Or 'C:/projects/docs/HUNGER_AWARENESS_04212008' should work as well.


John
 
A

A. Sinan Unur

(e-mail address removed) wrote in @w7g2000hsa.googlegroups.com:

[ don't quote sigs ]
Thanks! Would you happen to have an example? I only got it to work for
a UNIX path not a path on my local computer. It could be I didn't
escape the path right. For example, if I have "C:\projects\docs
\HUNGER_AWARENESS_04212008", would I have to pass it as "C:\\projects\
\docs\\HUNGER_AWARENESS_04212008"?

From perlfaq5:

Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp
\foo.exe` work?

We are not going to write your code for you when the documentation
contains both working examples and answers to frequently answered
questions.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
K

kimanhtle

(e-mail address removed) wrote in @w7g2000hsa.googlegroups.com:

[ don't quote sigs ]


Thanks! Would you happen to have an example? I only got it to work for
a UNIX path not a path on my local computer. It could be I didn't
escape the path right. For example, if I have "C:\projects\docs
\HUNGER_AWARENESS_04212008", would I have to pass it as "C:\\projects\
\docs\\HUNGER_AWARENESS_04212008"?

From perlfaq5:

Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp
\foo.exe` work?

We are not going to write your code for you when the documentation
contains both working examples and answers to frequently answered
questions.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:http://www.rehabitation.com/clpmisc/

$upload_dir = 'C:\projects\docs\HUNGER_AWARENESS_04212008';
$upload_dir =~ s/\\/\//g;
find(\&handleFind, $upload_dir);

sub handleFind {
my $foundFile = $File::Find::name;
print "$foundFile and $_<br/>\n";
}

That was what I tried and it did not print the results of the
directory. But thank you all for taking the time to reply and bearing
with a newbie. I believe it is b/c my Perl script is on a UNIX server
that is trying to read directories on a local PC.
 
J

John W. Krahn

$upload_dir = 'C:\projects\docs\HUNGER_AWARENESS_04212008';
$upload_dir =~ s/\\/\//g;
find(\&handleFind, $upload_dir);

sub handleFind {
my $foundFile = $File::Find::name;
print "$foundFile and $_<br/>\n";
}

That was what I tried and it did not print the results of the
directory. But thank you all for taking the time to reply and bearing
with a newbie. I believe it is b/c my Perl script is on a UNIX server
that is trying to read directories on a local PC.

UNIX does not have drive letters like 'C:' so it makes no sense to use
that as part of the path on a UNIX system.

So the question then becomes how are you accessing the directories "on a
local PC"? Via SMB? NFS? FTP? SSH? ???


John
 
K

kimanhtle

UNIX does not have drive letters like 'C:' so it makes no sense to use
that as part of the path on a UNIX system.

So the question then becomes how are you accessing the directories "on a
local PC"? Via SMB? NFS? FTP? SSH? ???

John

I am at a dead end. I was trying to use the file upload field to have
user select a file then use javascript to get the directory name of
that file. This directory name was passed to a CGI script which I
thought I could use to traverse the directory listing recursively.
Then the CGI script would upload all the files in this directory.
However, now I am stuck at finding a way to recursively read a
directory on my local PC.
 
B

Ben Bullock

I am at a dead end. I was trying to use the file upload field to have
user select a file then use javascript to get the directory name of that
file. This directory name was passed to a CGI script which I thought I
could use to traverse the directory listing recursively. Then the CGI
script would upload all the files in this directory. However, now I am
stuck at finding a way to recursively read a directory on my local PC.

There isn't any way for the Unix server to read the directory on your
local PC solely via a web browser, at least unless you totally disable
all security in the browser or something. Imagine if it was possible to
do things like that, we'd all be in serious trouble! You can send the
string containing the directory to the Unix server, but unless the Unix
server has some file system type of connection to your local PC (that is
the "SMB? NFS? FTP? SSH?" stuff which JK mentioned), it's not possible
to look at the PC's file system with either a CGI script or JavaScript.
That is just the nature of web servers and browsers.
 
T

Ted Zlatanov

On Wed, 23 Apr 2008 05:19:39 -0700 (PDT) (e-mail address removed) wrote:

k> I am at a dead end. I was trying to use the file upload field to have
k> user select a file then use javascript to get the directory name of
k> that file. This directory name was passed to a CGI script which I
k> thought I could use to traverse the directory listing recursively.
k> Then the CGI script would upload all the files in this directory.
k> However, now I am stuck at finding a way to recursively read a
k> directory on my local PC.

Unfortunately the currently available standards only let you upload one
file at a time. On the client, make a ZIP (or other format) archive of
the whole directory tree of interest and upload that. On the server,
open and examine the archive with Archive::Zip or whatever module is
appropriate for the archive format you've chosen.

Ted
 
K

kimanhtle

On Wed, 23 Apr 2008 05:19:39 -0700 (PDT) (e-mail address removed) wrote:

k> I am at a dead end. I was trying to use the file upload field to have
k> user select a file then use javascript to get the directory name of
k> that file. This directory name was passed to a CGI script which I
k> thought I could use to traverse the directory listing recursively.
k> Then the CGI script would upload all the files in this directory.
k> However, now I am stuck at finding a way to recursively read a
k> directory on my local PC.

Unfortunately the currently available standards only let you upload one
file at a time.  On the client, make a ZIP (or other format) archive of
the whole directory tree of interest and upload that.  On the server,
open and examine the archive with Archive::Zip or whatever module is
appropriate for the archive format you've chosen.

Ted

Thank you all so much for your help.
Ben, you are right, I did think of the security issue. But my boss
kept telling me there was a way to do recursive find. I searched the
web and found I could use an applet and then a perl script in the
backend. However, boss did not approve using applet.
Ted, the zip method was my last resort which I have working.
 
P

Peter J. Holzer

There isn't any way for the Unix server to read the directory on your
local PC solely via a web browser, at least unless you totally disable
all security in the browser or something. Imagine if it was possible to
do things like that, we'd all be in serious trouble! You can send the
string containing the directory to the Unix server, but unless the Unix
server has some file system type of connection to your local PC (that is
the "SMB? NFS? FTP? SSH?" stuff which JK mentioned), it's not possible
to look at the PC's file system with either a CGI script or JavaScript.

I think it is possible to give signed JavaScript the permission to do
this (similar to signed applets). But I've never looked at the details
and it's off-topic in this group anyway.

hp
 
A

A. Sinan Unur

I think it is possible to give signed JavaScript the permission to do
this (similar to signed applets). But I've never looked at the details
and it's off-topic in this group anyway.

AFAIK, works only on Firefox. So, if that is a suitable restriction for
the OP, the next place to check is Firefox documentation on how to do
it.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 

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

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top