Neil,
This is a little sub that I rolled up to provide the path,
filename, and extension:
sub Fparse($)
{ local $_ = shift; my ($Delim, $Fp, $Fn, $Fe, $Pos1, $Pos2); # Check whether the filename contains
forward or backward slashes.
$Delim = (index($_,'/') > -1) ? '/' : '\\'; # Find the last slash in the
filename.
$Pos1 = rindex($_,$Delim); # Extract the path if
present.
if ($Pos1) {$Pos1++; $Fp = substr($_,0,$Pos1)} else {$Fp = undef; $Pos1 = 0} # Find the last period in the
filename.
$Pos2 = rindex($_,'.'); # Extract the name and
extension.
if ($Pos2) {$Fn = substr($_,$Pos1,$Pos2 - $Pos1); $Pos2++; $Fe = substr($_,$Pos2)} else {$Fn = substr($_,$Pos1); $Fe = undef}
return(($Fp,$Fn,$Fe));
} =item Fparse($filename)
=item
=over 4
This routine accepts a string as an argument that will contain
a
filename and will parse the filename into the path, name, and file extension. The parsed elements will be returned as an lvalue. An undef will be returned for elements that do not exist in the passed filename, i.e. path and/or file extension. You could select just the path like this, assuming $file
contains the fully qualified filename:
($path, undef, undef) = Fparse($file);
Dirk Bremer - Systems Programmer II - ESS/AMS - NISC St. Peters 636-922-9158 ext. 8652 fax 636-447-4471
|
- perl-win32-users - Best way to return a path to a fi... Neil
- RE: perl-win32-users - Best way to return a pat... Dirk Bremer \(NISC\)
- RE: perl-win32-users - Best way to return a pat... Edwards, Mark \(CXO\)
- Re: perl-win32-users - Best way to return a... michael higgins