Recursive directory read with File::Find

Recursive directory read with File::Find

am 23.04.2008 00:43:54 von 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?

Re: Recursive directory read with File::Find

am 23.04.2008 00:54:03 von someone

kimanhtle@gmail.com wrote:
> I would like to do a recursive read of a directory on my local
> computer. Is this possible with File::Find?

Yes.

> If not, is there any other way to do it in Perl?

TMTOWTDI

http://search.cpan.org/search?query=File%3A%3AFind&mode=all


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Re: Recursive directory read with File::Find

am 23.04.2008 05:14:23 von kimanhtle

On Apr 22, 6:54 pm, "John W. Krahn" wrote:
> kimanh...@gmail.com wrote:
> > I would like to do a recursive read of a directory on my local
> > computer. Is this possible with File::Find?
>
> Yes.
>
> > If not, is there any other way to do it in Perl?
>
> TMTOWTDI
>
> http://search.cpan.org/search?query=File%3A%3AFind&mode=all
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall


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"?

Re: Recursive directory read with File::Find

am 23.04.2008 05:21:52 von someone

kimanhtle@gmail.com wrote:
>
> On Apr 22, 6:54 pm, "John W. Krahn" wrote:
>>
>> kimanh...@gmail.com wrote:
>>>
>>> I would like to do a recursive read of a directory on my local
>>> computer. Is this possible with File::Find?
>>
>> Yes.
>>
>>> If not, is there any other way to do it in Perl?
>>
>> TMTOWTDI
>>
>> http://search.cpan.org/search?query=File%3A%3AFind&mode=all
>
> 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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Re: Recursive directory read with File::Find

am 23.04.2008 05:22:53 von 1usa

kimanhtle@gmail.com wrote in news:9c1c4e83-24cb-4a0a-a888-9f191ff99111
@w7g2000hsa.googlegroups.com:

> On Apr 22, 6:54 pm, "John W. Krahn" wrote:
>> kimanh...@gmail.com wrote:
>> > I would like to do a recursive read of a directory on my local
>> > computer. Is this possible with File::Find?
>>
>> Yes.
>>
>> > If not, is there any other way to do it in Perl?
>>
>> TMTOWTDI
>>
>> http://search.cpan.org/search?query=File%3A%3AFind&mode=all
>>
>> John
>> --

[ 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 <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

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

Re: Recursive directory read with File::Find

am 23.04.2008 06:36:32 von kimanhtle

On Apr 22, 11:22 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> kimanh...@gmail.com wrote in news:9c1c4e83-24cb-4a0a-a888-9f191ff99111
> @w7g2000hsa.googlegroups.com:
>
> > On Apr 22, 6:54 pm, "John W. Krahn" wrote:
> >> kimanh...@gmail.com wrote:
> >> > I would like to do a recursive read of a directory on my local
> >> > computer. Is this possible with File::Find?
>
> >> Yes.
>
> >> > If not, is there any other way to do it in Perl?
>
> >> TMTOWTDI
>
> >>http://search.cpan.org/search?query=File%3A%3AFind&mode=al l
>
> >> John
> >> --
>
> [ 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 <1...@llenroc.ude.invalid>
> (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 $_
\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.

Re: Recursive directory read with File::Find

am 23.04.2008 08:11:10 von someone

kimanhtle@gmail.com wrote:
> On Apr 22, 11:22 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>>
>> From perlfaq5:
>>
>> Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp
>> \foo.exe` work?
>
> $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 $_
\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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Re: Recursive directory read with File::Find

am 23.04.2008 14:19:39 von kimanhtle

On Apr 23, 2:11 am, "John W. Krahn" wrote:
> kimanh...@gmail.com wrote:
> > On Apr 22, 11:22 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>
> >> From perlfaq5:
>
> >> Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp
> >> \foo.exe` work?
>
> > $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 $_
\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
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall

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.

Re: Recursive directory read with File::Find

am 23.04.2008 14:31:38 von benkasminbullock

On Wed, 23 Apr 2008 05:19:39 -0700, kimanhtle wrote:

> 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.

Re: Recursive directory read with File::Find

am 23.04.2008 15:27:04 von Ted Zlatanov

On Wed, 23 Apr 2008 05:19:39 -0700 (PDT) kimanhtle@gmail.com 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

Re: Recursive directory read with File::Find

am 23.04.2008 16:23:13 von kimanhtle

On Apr 23, 9:27=A0am, Ted Zlatanov wrote:
> On Wed, 23 Apr 2008 05:19:39 -0700 (PDT) kimanh...@gmail.com 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. =A0On the client, make a ZIP (or other format) archive of
> the whole directory tree of interest and upload that. =A0On 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.

Re: Recursive directory read with File::Find

am 23.04.2008 19:01:37 von hjp-usenet2

On 2008-04-23 12:31, Ben Bullock wrote:
> On Wed, 23 Apr 2008 05:19:39 -0700, kimanhtle wrote:
>> 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.

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

Re: Recursive directory read with File::Find

am 24.04.2008 01:45:06 von 1usa

"Peter J. Holzer" wrote in
news:slrng0uqri.5jo.hjp-usenet2@hrunkner.hjp.at:

> On 2008-04-23 12:31, Ben Bullock wrote:
....

>> 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.

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 <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

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