Link to home
Start Free TrialLog in
Avatar of sbhegel
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/tomcat6-ui25/webapps";
@ENV = <$DIR/ui*>;

 foreach $env (@ENV) {
   print "$env <br>";
 }


RESULTS:
/reg00/app/Tomcat/tomcat6-ui25/webapps/uicrp01_25
/reg00/app/Tomcat/tomcat6-ui25/webapps/uicrp03_25
/reg00/app/Tomcat/tomcat6-ui25/webapps/uiedi01_25


Instead of the full path of /reg00/app/Tomcat/tomcat6-ui25/webapps/uicrp01_25, I just want uicrp01_25.

Thanks
Avatar of Adam314
Adam314


$DIR="/reg00/app/Tomcat/tomcat6-ui25/webapps";
opendir(DIR, $DIR);
@ENV = grep /^ui/ readdir();

Open in new window

Avatar of sbhegel

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?
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sbhegel

ASKER

Thanks, that worked great.
Avatar of Tintin
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