in reply to Re: Re: Parse out the extension of a filename - return base of filename.
in thread Parse out the extension of a filename - return base of filename.
Umm.. try running the example he gave (or reading the node more closely). It does match the last part of the filename following the final dot. So if you run:
perl -MFile::Basename -e 'print join ":", fileparse("foo.bar.baz", "\\ +.[^.]+"), "\n"'
It produces foo.bar as the filename, ./ as the directory and baz as the extension. A few more filenames and results follow:
Input filename | Base name | Extension |
foo.bar.baz | foo.bar | baz |
foo.bar | foo | bar |
foo | foo | none |
-ben
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Knob Re: Parse out the extension of a filename - return base of filename.
by snafu (Chaplain) on Mar 13, 2002 at 14:47 UTC |
In Section
Cool Uses for Perl