Alex Alex - 2 months ago 9x Question

VB.NET Retrieve File path of File in Parent directory without parent Directory path included

So I have a directory where i want to get for all files in all including subdirs, the path of them relative to the parent directory.

Parent directory: "C:\test"
File1 located in: "C:\test\foo\bar.txt"

what i want to retrieve is:


I know how to do it with

For Each foundFile As String In My.Computer.FileSystem.GetFiles(Path)

but that will return the full Path to me.


So you have:

    Dim root = "c:\temp\"
    Dim files = My.Computer.FileSystem.GetFiles(root, FileIO.SearchOption.SearchAllSubDirectories)

Now just take the substring starting at the length of the root directory.

    Dim filesWithoutRoot = files.Select(Function(f) f.Substring(root.Length)).ToList