How can I open a directory and check if the content inside has another directory .If there is a directory, I want it to be opened again and again checked for any other directory.This process has to be repeated till it reaches a folder called "STAGING". Then the script generates the absolute path till the parent directory of STAGING.
For Windows in my mind comes a quick trick - command "dir"
A little example:
-
use strict;
-
#define variables
-
my ($path) = @ARGV;
-
my $absolutePath;
-
-
#open virtual file -> see dir /?
-
open(DIR, "dir $path /A:D /S /B|");
-
-
#until end of file do something
-
while(<DIR>){
-
if(/STAGING/){
-
$absolutePath = $_; #set your needed value
-
last; #end the while, we found what we want
-
}
-
}
-
-
#print result
-
print $absoultePath;
-
this example works only for windows
for linux is command "ls", but i don't have too much experience with unix/linux systems.
Other way is to use a recursive function with opendir, chdir and verify if the name is what we are looking for. The problem there is that we look into a matrix and you have to determinate how to look(depth or breadth), it's a little more complicate. If this example doesn't suite you, and you didn't get your answer yet, please let a note and i will try to find time to write the recursive example for you.