CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Sub Directories

 



billydean
Deleted

Mar 27, 2000, 2:03 PM

Post #1 of 7 (1828 views)
Sub Directories Can't Post

If I open a directory how can I list all the sub directories?

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

opendir(DIR, $path);
@a=grep(/?/, readdir(DIR));
closedir(DIR);</pre><HR></BLOCKQUOTE>

Can I replace the ? with something to do it.


Cure
User

Mar 27, 2000, 4:26 PM

Post #2 of 7 (1828 views)
Re: Sub Directories [In reply to] Can't Post

Hi

This will work for you.

$path='/path to directory/';
opendir(DIR, "$path") or die "$!";
@dir=readdir DIR;
closedir(DIR);

print @dir;


Cure


billydean
Deleted

Mar 27, 2000, 5:50 PM

Post #3 of 7 (1828 views)
Re: Sub Directories [In reply to] Can't Post

That will display all the files in a directory, but i want a list of all the sub directories. Like the names of folders in that directory, excluding the files. Is there a way i can just get rid of the files from that list?


Cure
User

Mar 27, 2000, 5:55 PM

Post #4 of 7 (1828 views)
Re: Sub Directories [In reply to] Can't Post

Hi

This code will work for you..(just put this cgi in your directory that you want to list the sub-directories).

#!/usr/bin/perl
use File::Find;

print "Content-type: text/html\n\n";


find(\&wanted, '.');

sub wanted {
( -d $_ ) && print "$File::Find::name\n";
}


Cure

[This message has been edited by Cure (edited 03-27-2000).]


Cure
User

Mar 27, 2000, 7:51 PM

Post #5 of 7 (1828 views)
Re: Sub Directories [In reply to] Can't Post

Hi

This code will work for you also::

#!/usr/bin/perl

print "Content-type: text/html\n\n";


$path='/path/to/dir';

opendir(DIR, $path) &#0124; &#0124; die "could not open '$path' directory $!";

@cure=grep(-d "$path/$_", readdir(DIR));

closedir(DIR);


print @cure;

Cure


billydean
Deleted

Mar 29, 2000, 1:16 PM

Post #6 of 7 (1828 views)
Re: Sub Directories [In reply to] Can't Post

Thanks for all the help!


Cure
User

Mar 29, 2000, 3:30 PM

Post #7 of 7 (1828 views)
Re: Sub Directories [In reply to] Can't Post

Your Welcome::

Cure

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives