By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 2,763 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Counting Files in a folder

P: n/a
Re: Access 2000

How can I loop through a folder on the user's hard drive, and check to
see if it is an .mdb file. If it is an .mdb, do some stuff, else go
to the next filename?

Can this be done without using recordsets?

Thanks,

RLN
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 5 Jan 2004 15:01:37 -0800, rl**********@yahoo.com (Ron Nolan)
wrote:
Re: Access 2000

How can I loop through a folder on the user's hard drive, and check to
see if it is an .mdb file. If it is an .mdb, do some stuff, else go
to the next filename?

Can this be done without using recordsets?

Thanks,

RLN


Take a look at the Dir() function in help.

- Jim
Nov 12 '05 #2

P: n/a
In article <13**************************@posting.google.com >,
rl**********@yahoo.com (Ron Nolan) writes:
Re: Access 2000

How can I loop through a folder on the user's hard drive, and check to
see if it is an .mdb file. If it is an .mdb, do some stuff, else go
to the next filename?

Can this be done without using recordsets?

Thanks,

RLN


Ron

Here is a function that I have used before:

Function fCountFilesInDir(strDir As String, Optional varFileType As Variant) As
Long
' A function to count the number of files in a directory (excluding
directories)
' Accepts:
' strDir - the directory to count the files in, i.e. "C:\Folder\"
' varFileType (optional) - a file extension if you only wish to count
certain file types, i.e. "exe"
' Returns:
' The number of files in the directory
On Error GoTo E_Handle
Dim strFile As String
Dim lngCount As Long
strFile = Dir(strDir, vbNormal)
Do While strFile <> ""
If Not IsMissing(varFileType) Then
If Right(strFile, Len(varFileType)) = varFileType Then lngCount =
lngCount + 1
Else
lngCount = lngCount + 1
End If
strFile = Dir
Loop
fCountFilesInDir = lngCount
fExit:
Exit Function
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume fExit
End Function
--

Jon

www.applecore99.com - Access Tips and Tricks

Nov 12 '05 #3

P: n/a
R N
Hey Jon, thanks for the tip here, I appreciate your help a bunch!

Cordially,

---------------
RLN

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.