Powershell file directoy question

Posted on 2012-09-03
Last Modified: 2012-09-04
I have a file in the following location


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


and if possible


Many thanks
Question by:Total_Nutter
    LVL 77

    Accepted Solution

    not elegant but it works
    $a = "c:\data\users\sales\reps\"
    $b = Split-Path $a -Leaf
    $c = Split-Path $a -Parent
    $d = split-path $c -leaf
    $e = "\" + $d + "\" + $b + "\"
    $f = "c:\.."+$e
    LVL 8

    Expert Comment

    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
            [string]$Prefix = ""
        return ($Prefix +  $fullPath.Substring($maskPath.Length))

    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",

    Author Closing Comment

    Simple, but works - many thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
    Several part series to implement Internet Explorer 11 Enterprise Mode
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now