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: Intermediate:
Locating Directories with a certain name.

 



trirnoth
New User

Jul 29, 2008, 7:56 AM

Post #1 of 2 (310 views)
Locating Directories with a certain name. Can't Post

Apologies if this has been posted before or if I am missing something obvious. I have searched but not found anything that specifically has the same requirements.

I need to find a method to store all the users home directories in an array.

A users directory can be in any of the following locations...
/home/domains/testdomain.tld/username/ OR /home/domains/testdomain.tld/number/username/ OR /home/domains/testdomain.tld/number/number/username/ ...

Maildir is always the only folder within the home directory, so I figured I could use the following to find the above directories:
my @serverDirectories = qx(find /home/domains/ -type d | egrep Maildir\$ | sed 's/\\/Maildir//');
But this has proven to be very very slow due to the number of directories.

I can't use maxdir since I'm not sure how far down a directory might be. IE: how many numbers may exist in a users' directory path.

The above then gets compared to a database of users' folders where orphaned (not in the database) folders would then be removed.

What is slowing this down is that even after finding the directory Maildir, this keeps searching within this folder.

I'm thinking I could use some sort of recursive algorithm to search for the first instance of Maildir within a folder then move onto the next one, but I am having problems visualizing how I would go about this.

Thanks for making it this far.


trirnoth
New User

Jul 30, 2008, 8:32 AM

Post #2 of 2 (289 views)
Re: [trirnoth] Locating Directories with a certain name. SOLVED [In reply to] Can't Post

With help from the Perl IRC, I was pointed to "prune".
I did not do a good job reading through the docs for File::Find.


Code
find(\&maildir, "/home/domains/"); 
sub maildir {
/Maildir/ and $File::Find::prune = 1;
if ($_ eq 'Maildir') {
push(@serverDirectories, "$File::Find::dir");
}
}


 
 


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

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