Jul 29, 2008, 7:56 AM
Post #1 of 2
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.
Locating Directories with a certain name.
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.