-1

Suppose I have the directory path:

D:\aa\bb

and inside of it can be more file or folders with sub folders

for example

D:\aa\bb\test.txt
D:\aa\bb\cc\test.txt
D:\aa\bb\cc\dd\test.txt

is there a clean way to extract the right part of the path?

I need something like:

string ExtractRightPart(string fullPath)
{
   return ...
}

Examples:

For input

D:\aa\bb\cc\dd\test.txt

the function should return

cc\dd\test.txt

And for input

D:\aa\bb\test.txt

the function should return

test.txt
spez
  • 409
  • 8
  • 21

1 Answers1

1
    public string ExtractRightPart(string fullPath, string leftPath)
    {
        return fullPath.Substring(leftPath.Length);
    }

    ExtractRightPart(@"D:\aa\bb\cc\dd\test.txt", @"D:\aa\bb\");
Philippe Auriou
  • 567
  • 4
  • 17