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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Processing files in a folder

Status
Not open for further replies.

morcelli

Technical User
Jul 28, 2002
4
0
0
AU
Hi,

I'm stuck trying to open files in a folder, one at a time, processing, then closing them. Is there a way of treating a folder as a recordset & the files as records? I don't want to enter the filenames in a table first, all 200 of them every week! It would be nice to specify a folder and all files in it be processed.

Thanks,

Morcelli
 
You can list files in a particular folder using the following...
If you want to you can replace the msgbox with some code to write the file paths to a table, then use this table to do the processing on each file.
To only act on files of a particular type change msoFileTypeAllFiles to one of the other available constants.


Private Sub mFindFile()
Dim strPath As String
Dim fs As FileSearch
Dim intCount As Integer

strPath = "C:\winnt"

ChDir strPath
Set fs = Application.FileSearch
With fs
.LookIn = strPath
.FileType = msoFileTypeAllFiles
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For intCount = 1 To .FoundFiles.Count
MsgBox .FoundFiles(intCount)
Next intCount
Else
MsgBox "There were no files found."
End If
End With
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top