sub get_sub_dirs { #Made by: cynix #Local Variable for Path Passed to This Sub local($tmp_path) = @_; #<------ OPEN THE REQUESTED DIR PATH AND GET A FILE LISTING ------ opendir(TMP_DIR, $tmp_path) || die "Cannot Open $tmp_path"; local(@tmp_dir_listing) = readdir(TMP_DIR); closedir(TMP_DIR); #----------------------------------------------------------------- #NOTE THE CODE: local($nmbr_items) = @some_array; #DOESNT WORK SO ALWAYS DECLARE IT FIRST. local($nmbr_items); $nmbr_items = @tmp_dir_listing; #Variable to Hold the "Clean" Directory Listing local(@tmp_clean_listing); #Variable to Hold Index Count for "Clean" Listing local($nmbr_clean_items) = 0; #INIT THE "Clean" DIR listing to "empty" #YOU CAN MODIFY THIS VARIABLE TO RETURN WHATEVER YOU #WANT IN CASES WHERE THERE WAS NO DIRECTORY FOUND $tmp_clean_listing[0] = 0; #Variable to Hold a Directory Index String local($item); #Change the Working Directory, so PERL can do File Test Operations chdir $tmp_path; #Scan Through Array, Excluding the Notorious '.' & '..' for ($i=2;$i<$nmbr_items;$i++) { $item = $tmp_dir_listing[$i]; #Test $item and See if it Really is a Dir if (-d $item) { #ITEM IS A DIR -> SO EXTRACT IT TO THE CLEAN ARRAY $tmp_clean_listing[$nmbr_clean_items] = $tmp_dir_listing[$i]; $nmbr_clean_items = $nmbr_clean_items + 1; } else { #DO NOTHING::ITEM IS NOT A DIR } } return(@tmp_clean_listing); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Return an Array of Sub-Dir Names
by wog (Curate) on Sep 09, 2001 at 04:36 UTC | |
|
Re: Return an Array of Sub-Dir Names
by merlyn (Sage) on Sep 09, 2001 at 22:00 UTC | |
by AltBlue (Chaplain) on Sep 26, 2001 at 00:46 UTC | |
|
Re: Return an Array of Sub-Dir Names
by blakem (Monsignor) on Sep 09, 2001 at 04:51 UTC |