Consulting

Results 1 to 6 of 6

Thread: Solved: Using Dir()

  1. #1

    Solved: Using Dir()

    I'm trying to access files thats are two levels deeper than the chosen path.

    For example:

    1 level down there are folders named "ADM", "QM", "ENG"
    2 levels down there are folders named "BP", "FO", "STD"

    I was wondering if I could put a sort of placeholder in the "\*.xls" part of the line of code below.

    FileName = Dir(Path & "\*.xls", vbNormal)

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    will the following code in the KB assist you?
    http://www.vbaexpress.com/kb/getarticle.php?kb_id=837
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why not just use

    [VBA]FileName = Dir(Path & "\ADM\BP\*.xls", vbNormal)[/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    to get all found files into a string:

    [vba]
    Sub tst()
    MsgBox CreateObject("wscript.shell").exec("cmd /c dir G:\OF\*.xls /b /s").stdout.readall
    End Sub
    [/vba]

    to get all found files in an array
    [vba]
    Sub tst()
    sn= split(CreateObject("wscript.shell").exec("cmd /c dir G:\OF\*.xls /b /s").stdout.readall,vbCrlf)
    End Sub
    [/vba]

  5. #5
    I did that, and it worked. However there are too many folders and the code becomes too long to execute.




    Quote Originally Posted by xld
    Why not just use

    [vba]FileName = Dir(Path & "\ADM\BP\*.xls", vbNormal)[/vba]

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    So what determines how many levels you look down?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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