Reputation: 664
I am trying to write a Visual Basic program that gets the names of all subdirectories within a directory, writes them into an array, and then writes the contents of the array to a dat file. I am however having a problem with the arrays not filling up with the directory names. Here's a piece of my code below.
For Each directoryName As String In IO.Directory.GetDirectories(appdata)
allAppdataDirectories(appdataNameId) = Dir(appdata)
appdataNameId += 1
ReDim Preserve allAppdataDirectories(appdataNameId)
Next
The above code snippet is supposed to get all of the directory names within my appdata folder. Assuming variable and array in this code has been declared already, what is wrong with it? I know that writing to the data file is working because I have done it in another context in this program and it works just fine.
Upvotes: 0
Views: 114
Reputation: 155
You are not using the directoryName variable Maybe it also would be easiest to use a list insted of an array Check if this solution can work for you :
Dim allAppDataDirectories As New List(Of String)
For Each directoryName As String In IO.Directory.GetDirectories(appData)
allAppDataDirectories.Add(directoryName)
Next
'Finally, if you need an array you can use allAppDataDirectories.ToArray()
Upvotes: 1