Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
rege just want to get file name not the extension
madmax
opendir DCRDIR, "$iwmount/default/main/al/WORKAREA/x/templatedata/data/" or die "serious dainbramage: $!";
@files
= grep (!/^\./,readdir (DCRDIR));
closedir(DCRDIR);
teamsite 6.1
os=unix
Find more posts tagged with
Comments
jed
This what you want? This should strip the extension...
my $file='foo.bar.text';
my($filename) = $file =~ m/(.*)\..*$/;
print "$filename\n";
--
Jed Michnowicz
jedm@sun.com
Content Management Engineer
Sun Microsystems
madmax
thanks.
Adam Stoller
If you want to remove the extensions off of all the files in the directory - after you've done your readdir you could do something like:
s|\..*$|| foreach(
@files)
;
or - if you want to just remove the *last* extension (i.e. foo.bar.baz => foo.bar rather than just foo):
s|\.[^\.]*$|| foreach(
@files)
;
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
JeremyH
You could almost right a book on the number of different ways there are to do this in perl.
A few other alternatives:
1) File::BaseName
2) split the file on '.' and then join with all but the last.
3) and of course the many different regexes listed.