请问如何用vb.net遍历一个文件夹下的所有文件包括子文件夹?
请问如何用vb.net遍历一个文件夹下的所有文件包括子文件夹?
[解决办法]
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemiodirectoryclasstopic.asp
对于一个文件夹下,要分成文件和文件夹两种类型数据来获取。对于子文件夹还需要继续使用这种方法查找。
[解决办法]
Dim tmpFolders() As String = IO.Directory.GetDirectories(TargetFolder)
Dim tmpFiles() As String = IO.Directory.GetFiles(TargetFolder)
Dim tmp2Folders(), tmp2Files() As String
Dim i As Integer = 0
While i < tmpFolders.Length
tmp2Folders = IO.Directory.GetDirectories(tmpFolders(i))
ReDim Preserve tmpFolders(tmpFolders.Length + tmp2Folders.Length - 1)
tmp2Folders.Copy(tmp2Folders, 0, tmpFolders, tmpFolders.Length - tmp2Folders.Length, tmp2Folders.Length)
tmp2Files = IO.Directory.GetFiles(tmpFolders(i))
ReDim Preserve tmpFiles(tmpFiles.Length + tmp2Files.Length - 1)
tmp2Files.Copy(tmp2Files, 0, tmpFiles, tmpFiles.Length - tmp2Files.Length, tmp2Files.Length)
i += 1
End While
TargetPaths = tmpFiles