Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Traversing folders

Reply
Thread Tools

Traversing folders

 
 
Dirk
Guest
Posts: n/a
 
      07-11-2012
Hi,

I am new to Perl and I am trying to list all the folders within a given folder and I have the following code. I know it is simple but for some reason the program just stops and I am not seeing any error code being returned.

Does anybody have a good example of File::Find that they are willing to share. Examples are easier for me to follow.


#!/usr/bin/perl
#

use warnings;
use strict;
use File::Find;

my $path_name;
$path_name = '/test';

find sub {
return unless -d;
print "$File::Find::name\n";
},$path_name;

exit;
 
Reply With Quote
 
 
 
 
Rainer Weikusat
Guest
Posts: n/a
 
      07-11-2012
Dirk <(E-Mail Removed)> writes:
> I am new to Perl and I am trying to list all the folders within a
> given folder and I have the following code. I know it is simple but
> for some reason the program just stops and I am not seeing any error
> code being returned.


[...]

> #!/usr/bin/perl
> #
>
> use warnings;
> use strict;
> use File::Find;
>
> my $path_name;
> $path_name = '/test';
>
> find sub {
> return unless -d;
> print "$File::Find::name\n";
> },$path_name;
>
> exit;


Works for me.
 
Reply With Quote
 
 
 
 
Hans Mulder
Guest
Posts: n/a
 
      07-11-2012
On 11/07/12 17:40:59, Dirk wrote:
> Hi,
>
> I am new to Perl and I am trying to list all the folders within a given
> folder and I have the following code. I know it is simple but for some
> reason the program just stops and I am not seeing any error code being
> returned.
>
> #!/usr/bin/perl
> #
>
> use warnings;
> use strict;
> use File::Find;
>
> my $path_name;
> $path_name = '/test';
>
> find sub {
> return unless -d;
> print "$File::Find::name\n";
> },$path_name;
>
> exit;


Does '/test' exist on your system?

What happens if you try $path_name = '..'; ?

-- HansM

 
Reply With Quote
 
Rainer Weikusat
Guest
Posts: n/a
 
      07-12-2012
Ben Morrow <(E-Mail Removed)> writes:
> Quoth Dirk <(E-Mail Removed)>:


[...]

>> #!/usr/bin/perl
>> #
>>
>> use warnings;
>> use strict;
>> use File::Find;
>>
>> my $path_name;
>> $path_name = '/test';
>>
>> find sub {
>> return unless -d;
>> print "$File::Find::name\n";
>> },$path_name;
>>
>> exit;

>
> You don't need to call 'exit' unless you want to exit early, or with an
> error code. Falling off the end of a Perl program is the usual way to
> exit successfully.


JFTR: This is not necessarily always true. For instance, the embedded
perl interpreter Nagios may use for executing plugins written in Perl
complains about plugins which didn't exit 'properly' if there is no
explicit exit statement at the end of the code.
 
Reply With Quote
 
Dirk
Guest
Posts: n/a
 
      07-13-2012
Thanks to everybody for their input. When I first ran the code I was running it for a folder that did not have a lot of sub-folders. When I ran it agains a very large folder I could not verify all folders and it appeared thatI had some missing folders. After being able to verify all the folders andit appears that the code did return all sub-folders.

However, I did notice that I am getting a permission error. Something aboutnot being able to change directory.

Thanks again for all the replies.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
zipping files folders and sub folders w/ winzip or winrar Mike Computer Support 5 03-28-2008 09:10 PM
Desktop accesses laptop and reads folders but Laptop only accesses/opens Desktop but cannot read folders, access is denied onclejon Wireless Networking 3 11-01-2006 10:50 PM
NOTE: Storage on small folders, large folders, or one folder Pennywise@DerryMaine.Gov Computer Support 1 06-24-2006 09:09 AM
Syncing POP folders with IMAP folders Rich Computer Support 1 02-12-2004 09:36 PM
Traversing Access types in Modelsim steven VHDL 6 08-27-2003 01:04 PM



Advertisments