Search Tools Links Login

Recurse Subdirectories


Does anything you want to files in a directory and its subdirectories. For example, if you would like to add MP3's in a directory to a playlist in your MP3 player program, this would be handy for adding all of the files including those residing in subdirectories of that directory.

Original Author: Loc Nguyen

Code

'Create a DirListBox named "Dir1" and a FileListBox named "File1" and set their Visible properties to False
'Call:
'  DoDirs "C:MyDir", "*.mp3"
Public Sub DoDirs(DirPath As String, DirFilters As String)
  File1.Pattern = DirFilters
  Dir1.Path = DirPath
  DoFiles DirPath
  If Dir1.ListCount = 0 Then Exit Sub
  For k = 0 To Dir1.ListCount - 1
    Dir1.Path = DirPath
    DoDirs Dir1.List(k), DirFilters
    'DoEvents
  Next k
  Dir1.Path = DirPath
End Sub
Private Sub DoFiles(DirPath As String)
  File1.Path = DirPath
  If File1.ListCount = 0 Then Exit Sub
  For k = 0 To File1.ListCount - 1
    FileName = File1.Path & String(1 - Abs(CInt(Right(File1.Path, 1) = "")), "") & File1.List(k)
    'Place what you would like to do to the files here
    
  Next k
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 96 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.