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
Perl

Avatar of undefined
Last Comment
Tintin

8/22/2022 - Mon
Adam314


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

Open in new window

ASKER
sbhegel

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
Adam314

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
sbhegel

Thanks, that worked great.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
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