2016-08-17 4 views
1

私はすべてのサブディレクトリ内のすべてのファイルを取得するディレクトリを持ちます。そのディレクトリは親ディレクトリからの相対パスです。 例:VB.NET親ディレクトリを持たない親ディレクトリ内のファイルのファイルパスを取得

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

私は何を取得することです:

"foo\bar.txt" 

私は

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

でそれを行う方法を知っているが、それは私に完全なパスを返します。

答えて

1

だからあなたがいる:今ちょうどルートディレクトリの長さで始まる部分文字列を取る

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

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

ありがとう! – Alex

関連する問題