[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

splitpath

i'm looking for a sub that split the drive, path, filenename and extension from a complete pathname like the C function splitpath . i use the code above, but it won't work if the pathname had no extension or if there's no drive given.

sub makePath
{
$_[0] =~ /(.*:)(.*\/)(.*)(\..*)/;
return ($1, $2, $3, $4);
}
            

0
struppi
Asked:
struppi
1 Solution
 
prakashk021799Commented:
use File::Basename;

sub makePath
{
    fileparse_set_fstype('MSWin32');
    my ($name, $path, $ext) = fileparse(shift, '\..*');
    my $drive;
    ($drive, $path) = split ':', $path
        if $path =~ m/^[a-z]:/i;

    return ($drive, $path, $name, $ext);
}
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now