Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtaining list of file...

Status
Not open for further replies.

GSMike

Programmer
Feb 7, 2001
143
US
Using the dir function, I can obtain the list of files in a specified folder:
Code:
sub myproc()
dim mypath as string, myfile as string
mypath="c:\"
myfile=dir(mypath)
do until myfile=""
   msgbox myfile
   myfile=dir
loop
end myproc
What I am having a tortuous experience with is obtaining the list of files from all the subfolders (and the names of the subfolders) within "mypath". I also need the level at which a file is found. So, if the file is "c:\myfile.txt", the level is 1. If it is c:\temp\myfile.txt, the level is 2.

Can you give me any suggestions? Thanks in advance!! Mike K
 
Applications like this often lend themselves well to recursion. Basically, create a sub procedure like myproc that returns the files/folders that are at c:\...when it finds another folder, the procedure should recursively call itself. I believe you can use dir() to just return folder (so you can tell folder from files). To determine the level you are at, set up a loop that goes from 1 to len("c:\temp\folder\myFile.txt")...as you loop through each character, use the Mid() function to determine the number of "\" or "/" that you have...that should give you the level that you are at.

 
Just got it..in case anyone else is interested, here you go:
I couldn't make a reference that understood the ScriptingDictionary variable, so I just deleted all references to it, and replaced the line that says
Code:
dctDict.Add filFile.Path, filFile.Name
with
Code:
debug.print filfile.path, filfile.name
Mike K
 
Thank you, kieren.
I think we both arrived at the solution simultaneously.
I appreciate your help.
Mike K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top