Recursive directory read with File::Find
am 23.04.2008 00:43:54 von kimanhtleI 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?
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?
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
On Apr 22, 6:54 pm, "John W. Krahn"
> 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"?
kimanhtle@gmail.com wrote:
>
> On Apr 22, 6:54 pm, "John W. Krahn"
>>
>> 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
kimanhtle@gmail.com wrote in news:9c1c4e83-24cb-4a0a-a888-9f191ff99111
@w7g2000hsa.googlegroups.com:
> On Apr 22, 6:54 pm, "John W. Krahn"
>> 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/
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"
> >> 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.
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
On Apr 23, 2:11 am, "John W. Krahn"
> 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.
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.
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
On Apr 23, 9:27=A0am, Ted Zlatanov
> 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.
On 2008-04-23 12:31, Ben Bullock
> 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
"Peter J. Holzer"
news:slrng0uqri.5jo.hjp-usenet2@hrunkner.hjp.at:
> On 2008-04-23 12:31, Ben Bullock
....
>> 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/