TheManIsTheWind TheManIsTheWind - 3 months ago 15
Vb.net Question

Do not show the filename when outputting the string

I'm searching for a filename and outputting it to a textbox on my form. The search is working, but I do not want to output the filename i'm searching, only the filenames of the additional filenames I've found. Any ideas? Here's my code:

Dim pathway As String = "C:\myFolder\"
Dim dirs As String() = Directory.GetFiles(pathway, "myFile" & "*.xlsm")
If dirs.Length >= 1 Then
myTextBox.Text = "Additional Reports: " & vbCrLf & String.Join(", ", dirs.Select(Function(x) Path.GetFileNameWithoutExtension(x)))
End if

Answer

You can add an "except" filter to your enumeration:

Dim pathway As String = "C:\myFolder"
Dim fileName As String = "myFile"
Dim dirs As String() = Directory.GetFiles(pathway, fileName & "*.xlsm")
If dirs.Length >= 1 Then
  TextBox2.Text = "Additional Reports: " & Environment.NewLine &
    String.Join(", ", dirs.Select(Function(x) Path.GetFileNameWithoutExtension(x)) _
                          .Except(New String() {fileName}))
End If
Comments