Question

I am trying to make my app display folders in a specified directory, "Application.startupPath & "\Skins", and put them into a Combo Box. From the speech marks, you can probably see what I want the app to do. I posted an example of code I am trying to use. I have searched YouTube, Google, and even this site but no posts are helping.

Dim DirectorySkins As String = Application.StartupPath & "\Skins"
Try
    Dim Dir As DirectoryInfo = DirectCast(DirectorySkins, DirectoryInfo)
    For Each DirInfo As DirectoryInfo In Dir()


    Next
Catch ex As Exception
    ToolsError.ListBox1.Items.Add(ex.Message)
End Try

But I am getting the error:

Value of type 'String' cannot be converted to 'System.IO.DirectoryInfo'

in the DirectCast(DirectorySkins). I also get the error:

Class 'System.IO.DirectoryInfo' cannot be indexed because it has no default property.

This error is linked to the In Dir(). This code is based on a YouTube tutorial, so if it isn't what I'm looking for, then please let me know. Any help would be greatly appreciated. If you need any more information, I would be glad to provide it.

Was it helpful?

Solution

Try changing it to Dim DirectorySkins As New DirectoryInfo(Application.StartupPath & "\Skins"). Is this what you're trying to achieve?

Dim DirectorySkins As New DirectoryInfo(Application.StartupPath & "\Skins")

Try
    For Each DirInfo As DirectoryInfo In DirectorySkins.GetDirectories()


    Next
Catch ex As Exception
    ToolsError.ListBox1.Items.Add(ex.Message)
End Try
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top