Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB8.0 VB9.0 VB Windows VB10.0 , +
Hello,
 
Right now I am creating a vb.net 2010 project and I am having some issues with creating a sub function that will list all files including files in sub directories.
 
It is very easy to create a script that will list all files in a directory but not all sub directories.
Could someone please tell me the code that I need for this file listing function?
 
I know for C++ there is a project for this using C++.
I am looking for the same type of script but for VB.net.
 
http://www.codeproject.com/KB/files/GetFileList.aspx
 
Thank you Smile | :)
Posted 18-Aug-10 20:30pm
Edited 19-Aug-10 0:13am
v2
Comments
Dalek Dave at 19-Aug-10 5:14am
   
Minor Edit for Readability and Grammar.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Something like this might solve it for you:
 
Imports System.IO
 
Module Module1
 
    Sub Recurse(ByVal directory As DirectoryInfo, ByVal resultList As List(Of FileInfo))
        resultList.AddRange(directory.GetFiles())
 
        For Each subDirectory As DirectoryInfo In directory.GetDirectories()
            Recurse(subDirectory, resultList)
        Next
    End Sub
 

    Sub Main()
        Dim flatList As List(Of FileInfo)
 
        flatList = New List(Of FileInfo)
        Recurse(New DirectoryInfo("C:\Projects"), flatList)
 
        For Each f As FileInfo In flatList
            System.Console.WriteLine(f.FullName)
        Next
 

    End Sub
 
End Module
 
Hope this helps,
Fredrik
  Permalink  
Comments
Dalek Dave at 19-Aug-10 5:14am
   
5! Good answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 19 Aug 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100