Link to home
Start Free TrialLog in
Avatar of Total_Nutter
Total_Nutter

asked on

Powershell file directoy question

I have a file in the following location

c:\data\users\sales\reps\

Please could somebody help me with a  powershell script that will return only the following:

  \sales\reps\

and if possible

c:\..\sales\reps\

Many thanks
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I like to write my functionality as a function so that I cane make it more flexible, or if I think it would be of general use, I can add it to my profile.

Does this achieve what you require?

function Get-PartPath
{
    Param
    (
        [String]$FullPath,
        [string]$MaskPath,
        [string]$Prefix = ""
    )
    return ($Prefix +  $fullPath.Substring($maskPath.Length))
$path
}

Get-PartPath -FullPath "c:\data\users\sales\reps\" -MaskPath  "c:\data\users" -Prefix "c:\.."

If you always use the same value for the mask you could make it a default value:
 [string]$MaskPath =  "c:\data\users",
Avatar of Total_Nutter
Total_Nutter

ASKER

Simple, but works - many thanks