How do I remove the directory structure in file name in this function?
Hello,
I am listing files in a certain directory into a list box using the following code I found on this Forum (Thanks mpdeglau).
lstFiles.Items.AddRange(System.IO.Directory.GetFiles("C:\Test Files\Data Entry Process\", "*.XLS", IO.SearchOption.TopDirectoryOnly))
The file names are then listsed in the the list box but the problem is that it also includes the direcotry path also. like this.
C:\Test Files\Data Entry Process\test.xls
How do I have it not include the directory structure? so it would then just show
test.xls
Is there an option to do this?
Thanks for your help
Mythos
Re: How do I remove the directory structure in file name in this function?
You have to manually remove it from each file path (using System.IO.Path class) then add the file name to your list.
Code:
Dim theFiles() As String = System.IO.Directory.GetFiles("C:\Test Files\Data Entry Process\", "*.XLS", IO.SearchOption.TopDirectoryOnly)
For Each file As String In theFiles
lstFiles.Items.Add(System.IO.Path.GetFileName(file))
Next