Z
zampoot
Guest
I got this function which suppose to return all the writable paths in a given directory
I would like to get every writable directory in a drive
so I will use any drive letter as a directory
Private Function getAllFolders(ByVal directory As String) As String()
Dim fi As New IO.DirectoryInfo(directory)
Dim path() As String = {}
For Each subfolder As IO.DirectoryInfo In fi.GetDirectories()
Dim Attributes As System.IO.FileAttributes = My.Computer.FileSystem.GetFileInfo(subfolder.ToString).Attributes
If (fi.Attributes And FileAttributes.System) = 0 Then
If (Attributes And IO.FileAttributes.ReadOnly) <> 0 Then
Array.Resize(path, path.Length + 1)
path(path.Length - 1) = subfolder.FullName
For Each s As String In getAllFolders(subfolder.FullName)
Dim SubAttributes As System.IO.FileAttributes = My.Computer.FileSystem.GetFileInfo(s.ToString).Attributes
If (fi.Attributes And FileAttributes.System) = 0 Then
If (SubAttributes And IO.FileAttributes.ReadOnly) <> 0 Then
Array.Resize(path, path.Length + 1)
path(path.Length - 1) = s
End If
End If
Next
End If
End If
Next
Return path
End Function
for testing purpose I used this
For Each path In getAllFolders("E:\")
Dim myFile As String = "F:\paths.txt"
Using sw As StreamWriter = New StreamWriter(myFile, True)
Dim line As String = path.ToString
sw.WriteLine(line)
End Using
Next
but I keep getting an empty file, while I get paths when trying to use "C:\users\user\desktop" instead of a drive letter as the directory input for the function
So how to make it work with logical drives ?
Continue reading...