sbhegel
asked on
List Directories beginning with
I am trying to get a directory listing of all directories that begin with "ui" in a specified directory. I don't want to recurse down to any of the sub directories. I already have a piece of code that does it but the problem is it returns the full path of the directory where as I just want the directory name.
CODE:
$DIR="/reg00/app/Tomcat/to mcat6-ui25 /webapps";
@ENV = <$DIR/ui*>;
foreach $env (@ENV) {
print "$env <br>";
}
RESULTS:
/reg00/app/Tomcat/tomcat6- ui25/webap ps/uicrp01 _25
/reg00/app/Tomcat/tomcat6- ui25/webap ps/uicrp03 _25
/reg00/app/Tomcat/tomcat6- ui25/webap ps/uiedi01 _25
Instead of the full path of /reg00/app/Tomcat/tomcat6- ui25/webap ps/uicrp01 _25, I just want uicrp01_25.
Thanks
CODE:
$DIR="/reg00/app/Tomcat/to
@ENV = <$DIR/ui*>;
foreach $env (@ENV) {
print "$env <br>";
}
RESULTS:
/reg00/app/Tomcat/tomcat6-
/reg00/app/Tomcat/tomcat6-
/reg00/app/Tomcat/tomcat6-
Instead of the full path of /reg00/app/Tomcat/tomcat6-
Thanks
ASKER
Thanks for the example but not working correctly.
The line:
@ENV = grep /^ui/ readdir();
is causing an error when I try it.
Is there a syntax error in that somewhere?
The line:
@ENV = grep /^ui/ readdir();
is causing an error when I try it.
Is there a syntax error in that somewhere?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, that worked great.
or another way to do it is:
my $DIR="/reg00/app/Tomcat/tomcat6-ui25/webapps";
chdir $DIR or die "Can not cd to $DIR $!\n";
foreach my $env (<ui*>) {
print "$env <br>";
}
Open in new window