Oh wise ones,
I have 2 string variables (these will be dynamic) containing file system paths. As labeled one string ($BasePath) will contain the base / root path and the other string ($CurrentPath) will be the current path as the script is scanning the file system starting from the base path. What I am after is a string containing just the subdirectory without the base / root path.
Using the working example I have provided the result is what I am after \DirD\DirE
However, I am rather weak with regular expressions thus to me my solution seems to be rough and naturally only deals with the dreaded windows paths. I am hoping there may be a more efficient alternative that could be dynamic and also support unix paths.
my $BasePath = '\\DirA\DirB\DirC';
my $CurrentPath = '\\DirA\DirB\DirC\DirD\DirE';
$BasePath =~ s/\x5c/\x0d/g;
$CurrentPath =~ s/\x5c/\x0d/g;
$CurrentPath =~ s/$BasePath//;
$CurrentPath =~ s/\x0d/\x5c/g;
print "\n\$CurrentPath: ".$CurrentPath."\n";
Thanks in advance.