Results 1 to 3 of 3

Getting all sub folders and files within a folder

Threaded View

  1. #1
    Registered User
    Join Date
    06-09-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    92

    Getting all sub folders and files within a folder

    Hello all, I have the following problem:

    I run my sub which opens up a folder browser, however this only gets the folder, when I would like it to get files and sub folders within the folder.

    Function GetSubDir(ByVal sPath As String, Optional ByVal sPattern As Variant) As Variant
    
    Dim sDir As String
    Dim sDirLocationForText As String
    
    On Error GoTo Err_Clk
    
    If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
    
    If IsMissing(sPattern) Then
    sDir = Dir$(sPath, vbDirectory)
    Else
    sDir = Dir$(sPath & sPattern, vbDirectory)
    End If
    Do Until LenB(sDir) = 0
    
    If sDir <> "." And sDir <> ".." Then
    sDirLocationForText = sDirLocationForText & ";" & sPath & sDir
    End If
    sDir = Dir$
    
    Loop
    
    If Left$(sDirLocationForText, 1) = ";" Then sDirLocationForText = Right(sDirLocationForText, Len(sDirLocationForText) - 1)
    GetSubDir = sDirLocationForText
    End Function
    Any help would be greatly appreciated.
    Last edited by UsmanBPD; 03-05-2013 at 06:02 AM. Reason: wrong code
    Regards,
    Usman.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1