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!

Looping through files 1

Status
Not open for further replies.

Corbie

Technical User
Nov 19, 2001
21
GB
I need to go through all the files in a subdirectory and process them accordingly. I can handle all the actual processing, but how do you loop through all the files? I thought about writing the file names to a worksheet using Application.FileSearch then loop through the names, but is there a simpler/more elegant way to do it


Thanks for any help
 
Hi Corbie
You could use the FileSystemObject object's methods etc. An example:

Dim fs, f, f1, fc
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(Your folder with path)
Set fc = f.Files
For Each f1 In fc
' Do your thang here
Next f1

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Hi - try this
Sub LoopFilenames()
Dim filename As String

filename = Dir$("\\Yorkshire\Shared\Plans\*.tif")'change to whatever extension you're looking for
'Start File Search

Do While filename <> &quot;&quot;
msgbox = filename
filename = Dir$()
Loop
end sub Rgds
~Geoff~
 
Thanks guys - I'll try your suggestions out
and get back to you
 
Yes - Worked great - Thanks alot

Corbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top