4 Replies - 29837 Views - Last Post: 18 May 2010 - 06:00 PM Rate Topic: -----

#1 citricube  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 21-January 08

Generating a list of all files in folders, subfolders, subfolders of s

Posted 15 May 2010 - 12:51 PM

Hello fellow coders within the program i'm coding right now I would like to generate an arraylist of all files within a folder, its subfolders and those subfolders subfolders....

These are the functions i have to generate an arraylist of all folders in a folder along with all files in a folder
is there any more simple way to just search every file within a folder including all subfolders, and subfolders of subfolders?

 Function getDir(ByVal p As String) As ArrayList
        getDir = New ArrayList
        For Each s As String In My.Computer.FileSystem.GetDirectories(p)
            getDir.Add(s)
        Next
        Return getDir
    End Function
    Function getDir(ByVal ps As ArrayList) As ArrayList
        getDir = New ArrayList
        For Each s As String In ps
            If dirExist(s) Then
                For Each s2 As String In My.Computer.FileSystem.GetDirectories(s)
                    getDir.Add(s2)
                Next
            End If
        Next
        Return getDir
    End Function
    Function getFiles(ByVal p As String) As ArrayList
        getFiles = New ArrayList
        For Each s As String In My.Computer.FileSystem.GetFiles(p)
            getFiles.Add(s)
        Next
        Return getFiles
    End Function
    Function getFiles(ByVal ps As ArrayList) As ArrayList
        getFiles = New ArrayList
        For Each s As String In ps
            For Each s2 As String In My.Computer.FileSystem.GetFiles(s)
                getFiles.Add(s2)
            Next
        Next
        Return getFiles
    End Function


This post has been edited by citricube: 15 May 2010 - 01:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Generating a list of all files in folders, subfolders, subfolders of s

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1066
  • View blog
  • Posts: 4,173
  • Joined: 02-July 08

Re: Generating a list of all files in folders, subfolders, subfolders of s

Posted 15 May 2010 - 03:42 PM

What your looking for is a recursive directory search. In your function you have 1 parameter it is the first directory, then in your search you call you function to loof for directories in that directory this will only continue as long as there are directories. I would use a List(Of String) for the file names rather than an arraylist (I like them better). I would also use DirectoryInfo object too which has a GetFiles() with optional extension search - like when your just looking for "*.txt" files, it also has the GetDirectories() method which is where you would call your function again.
Was This Post Helpful? 0
  • +
  • -

#3 citricube  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 21-January 08

Re: Generating a list of all files in folders, subfolders, subfolders of s

Posted 15 May 2010 - 09:35 PM

Thank you hawkvalley I think i came across the DirectoryInfo object info on a google search I'll definitely look into that.

View Posthawkvalley1, on 15 May 2010 - 02:42 PM, said:

What your looking for is a recursive directory search. In your function you have 1 parameter it is the first directory, then in your search you call you function to loof for directories in that directory this will only continue as long as there are directories. I would use a List(Of String) for the file names rather than an arraylist (I like them better). I would also use DirectoryInfo object too which has a GetFiles() with optional extension search - like when your just looking for "*.txt" files, it also has the GetDirectories() method which is where you would call your function again.

Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Generating a list of all files in folders, subfolders, subfolders of s

Posted 15 May 2010 - 09:42 PM

There are a couple of examples in the Finding Files Tutorial (Snippet)
Was This Post Helpful? 1
  • +
  • -

#5 citricube  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 21-January 08

Re: Generating a list of all files in folders, subfolders, subfolders of s

Posted 18 May 2010 - 06:00 PM

That is precisely what i was looking for thanks a million Adam! :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1