anthonytr
asked on
Count the number of Files in a folder
Hi,
I'm trying to get an accurate count of the number of files in a given folder, however at the moment it seems to be returning with a value which is +1. I think this may be due to some hidden temp file in the folder or thumb. file .
My code currently is:
There will only ever be PDF, TIFF or (TIF) files stored in these folders, is there any way of only counting files with those extensions?
Thanks
I'm trying to get an accurate count of the number of files in a given folder, however at the moment it seems to be returning with a value which is +1. I think this may be due to some hidden temp file in the folder or thumb. file .
My code currently is:
Set objFiles = fso.GetFolder(strFolderName).Files
lngFileCount = objFiles.Count
MsgBox lngFileCount 'Total number of files
Me.number_of_items = lngFileCount
Set fsoFolder = Nothing
Set fso = Nothing
Me.Refresh
There will only ever be PDF, TIFF or (TIF) files stored in these folders, is there any way of only counting files with those extensions?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
I get a 'Compile Error'
For each control variable must be Variant or Object
I get a 'Compile Error'
For each control variable must be Variant or Object
For Each objFile In objFiles
oops sorry
change this
dim objFile as string
to
dim objFile as object
change this
dim objFile as string
to
dim objFile as object
ASKER
Hi Rey,
I missed that too! Thanks your code works perfectly.
Anthony
I missed that too! Thanks your code works perfectly.
Anthony
ASKER
Superb - thank you Rey
pls try
Open in new window
Regards