View Full Version : Solved: Using Dir()
sapcloasst
06-13-2012, 02:14 AM
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)
Aussiebear
06-13-2012, 02:31 AM
will the following code in the KB assist you?
http://www.vbaexpress.com/kb/getarticle.php?kb_id=837
Bob Phillips
06-13-2012, 02:38 AM
Why not just use
FileName = Dir(Path & "\ADM\BP\*.xls", vbNormal)
to get all found files into a string:
Sub tst()
MsgBox CreateObject("wscript.shell").exec("cmd /c dir G:\OF\*.xls /b /s").stdout.readall
End Sub
to get all found files in an array
Sub tst()
sn= split(CreateObject("wscript.shell").exec("cmd /c dir G:\OF\*.xls /b /s").stdout.readall,vbCrlf)
End Sub
sapcloasst
06-13-2012, 05:52 PM
I did that, and it worked. However there are too many folders and the code becomes too long to execute.
Why not just use
FileName = Dir(Path & "\ADM\BP\*.xls", vbNormal)
Bob Phillips
06-14-2012, 12:50 AM
So what determines how many levels you look down?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.