Iterate through files in a folder on Hard Drive

I

ibeetb

How do I iterate through file names in a folder on a hardrive? I already
have the code to set the Path and give me the name of ONE of the files....b
ut I can't seem to loop through to all files in the folder:
'This code just keeps repeating the same file name in the folder yet there
are 20 files in the folder. I need it to scroll through all 20
directory = "T:\Completed Models\"
f = Dir(directory & "*.xls", 7)
Do While f<>""
Result = directory & f
Loop
 
P

Patrick Molloy

almost there yourself ...

directory = "T:\Completed Models\"
f = Dir(directory & "*.xls", 7)
Do While f<>""
Result = directory & f f = Dir()
Loop


just the one additional line. Without any parameters, DIR
will return the next file in the last found folder

Patrick Molloy
Microsoft Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top