Lista filer med sökväg i en mapp
Följande kod lista upp alla filer i en mapp samt under mapp men inte innehållet i under mapp.
<code>
Dim Directory As New DirectoryInfo("C:\kurt\")
For Each File As FileSystemInfo In Directory.GetFileSystemInfos("*.*")
MsgBox(File.FullName)
Next
</code>
Följander resultat erhålles:
c:\Kurt\fil.txt
c:\Kurt\testmapp
Finns det något snabbt sätt att lista innehållet i undermappar så att resultatet blir som följer.
c:\Kurt\fil.txt
c:\Kurt\testmapp\fil.txtSv: Lista filer med sökväg i en mapp
Hittade följande kod men får inte till det när det stöts på en mapp med felrättigheter. Ide?
<code>
' Process all files in the directory passed in, recurse on any directories
' that are found, and process the files they contain.
Public Sub ProcessDirectory(ByVal targetDirectory As String)
' Process the list of files found in the directory.
Dim fileEntries As String() = Directory.GetFiles(targetDirectory)
For Each fileName As String In fileEntries
ProcessFile(fileName)
Next
' Recurse into subdirectories of this directory.
Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory)
For Each subdirectory As String In subdirectoryEntries
ProcessDirectory(subdirectory)
Next
End Sub
' Insert logic for processing found files here.
Public Sub ProcessFile(ByVal path As String)
Dim fi As New FileInfo(path)
ListBox1.Items.Insert(0, path)
End Sub
</code>