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

count the number of files in a folder 1

Status
Not open for further replies.

scottian

Programmer
Jul 3, 2003
955
GB
can anyone help with this.
i need to count the number of files in a location,
im using the code below but access seems to stick

---------------------------------------

Function CountCSV_files()
Dim FileName As String
Dim Count As Single

Count = 0
FileName = Dir("C:/*.csv")
If FileName <> &quot;&quot; Then
Do Until FileName = &quot;&quot;
Count = Count + 1
Loop
MsgBox Count
End If

---------------------------------------

any help is much appreciated
 
Couple of things that you need to take into account.

First of all, the solution to the problem is that you need to add a subsequent call to Dir inside the loop:

FileName = Dir(&quot;C:/*.csv&quot;)
If FileName <> &quot;&quot; Then
Do Until FileName = &quot;&quot;
Count = Count + 1
FileName = Dir
Loop

Also, be aware that if you have a sub-directory which meets that file qualitification (in this case unlikely), it will also be counted.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
cajun,
i have awarded you a star. the advice was perfect.
thanks
 
Thank you scottian, and glad I could help.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top