in reply to RegEx to get filepath for parent folder
use File::Basename; my $dirname = dirname ("lib/this/that/other.txt");
However, if you're sure that the path delimeter is a slash (either forward or backslash), and that the slash characters won't comprise part of a name, you could probably get away with a regexp like this:
($path, $filename) = $fullpath =~ m/^(.*[/\\])([^/\\]+)/;
Since it's easy to goof the Regexp (and mine is untested), you're better off using the module mentioned above. It's a lot better to rely on good tested code than a homebrewed complicated regexp, most of the time.
Update: I wanted to note that File::Spec and File::Basename are both part of the core Perl distribution, and thus, probably came standard with your implementation of Perl.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: RegEx to get filepath for parent folder
by Anonymous Monk on Mar 06, 2004 at 06:52 UTC |