Look for specific folder in all existing subfolders in main directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gehawk
    New Member
    • Nov 2013
    • 3

    Look for specific folder in all existing subfolders in main directory

    Hi everyone,

    I'm looking for a vba script which opens a subfolder in a maindirectory with only a part of the name known. I found something similar for files :

    http://bytes.com/topic/visual-basic/answers/827411-searching-main-folder-all-sub-folders-file

    example : c:\numbers\cars \10 big
    c:\numbers\cara vans\15 big

    If I fill in 15 and c:\numbers as maindirectory in vba the script should open the 15 big folder since 15 is in the name
  • 9815402440
    New Member
    • Oct 2007
    • 180

    #2
    following code may help you
    Code:
        Dim strT As String
        strT = Dir("c:\", vbDirectory)
        While strT <> Empty
            If InStr(1, strT, "w", vbTextCompare) > 0 Then
                Debug.Print strT
            End If
            strT = Dir()
        Wend

    Comment

    • gehawk
      New Member
      • Nov 2013
      • 3

      #3
      your code shows me the result in the immediate window.
      Could you advise me how to proceed? I only know some basic vba programming

      Comment

      • gehawk
        New Member
        • Nov 2013
        • 3

        #4
        Is this getting anywhere?

        Code:
        Dim f As Boolean
        
        Sub AAA()
            Dim FSO As Scripting.FileSystemObject
            Dim FF As Scripting.Folder
            f = False
            Set FSO = New Scripting.FileSystemObject
            Set FF = FSO.GetFolder("C:\Users\<username>\Desktop\testje")
            DoOneFolder FF
            If Not f Then
                MsgBox "File not found!", vbExclamation
            End If
        End Sub
        
        Sub DoOneFolder(FF As Scripting.Folder)
            
            Dim SubF As Scripting.Folder
            Dim strPath As String
            Dim strFile As String
            On Error GoTo ExitHandler
            If f Then Exit Sub
            strPath = FF.Path
            
            If Left(strPath, 1) <> "15" Then
                strPath = strPath & "\"
            End If
            
            For Each SubF In FF.SubFolders
                If Left(strPath, 1) = "15" Then
                Call Shell("explorer.exe " & strPath, vbNormalFocus)
                DoOneFolder SubF
            Next SubF
        ExitHandler:
        End Sub
        I found a code online and tried to adjust it
        Last edited by Rabbit; Nov 8 '13, 06:15 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.

        Comment

        Working...