|I am putting a list of files into a listbox from a directory and its subdirectories. Is there a way to remove the drive letter for each file but keep the other file information. For example:|
Original Entry = C:\Test\Folder\testfile1
How it shows up in the listbox = Test\Folder\testfile1
Here is my code so far:
Public Class Form1
Private Sub btnStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim CopyFiles As List(Of String) = GetData(SourcePath)
' Loop through and display each path.
Dim file As String
For Each file In CopyFiles
' Write total number of paths found.
TotalBox.Text = (CopyFiles.Count)
Public Shared Function GetData(ByVal initial As String) As List(Of String)
' This list stores the results.
Dim result As New List(Of String)
' This stack stores the directories to process.
Dim stack As New Stack(Of String)
' Add the initial directory
' Continue processing for each stacked directory
Do While (stack.Count > 0)
' Get top directory string
Dim dir As String = stack.Pop
' Add all immediate file paths
' Loop through all subdirectories and add them to the stack.
Dim directoryName As String
For Each directoryName In Directory.GetDirectories(dir)
Catch ex As Exception
' Return the list