Thursday, April 16, 2009

Retrieve All Files in the specified Folder

Private Sub getCompleteFileList(ByVal rootDir As String, ByRef arrFileList As ArrayList)
If My.Computer.FileSystem.GetDirectoryInfo(rootDir).Name = "System Volume Information" Then
Return
End If
For Each recursiveDir As String In My.Computer.FileSystem.GetDirectories(rootDir)
Call getCompleteFileList(recursiveDir, arrFileList)
Next
For Each foundFile As String In My.Computer.FileSystem.GetFiles(rootDir,FileIO.SearchOption_
.SearchTopLevelOnly)
arrFileList.Add(foundFile)
Next
End Sub

rootDir can be root drive or some specific directory. arrFileList is the final list of files in rootDir' all subDir,Sub-SubDir,Sub-Sub-SubDir................ means all the existing files, no matter how much deeper, are added in th earrFileList that can be used for any needed purpose requiring all the list of files in some dir.

No comments: