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

Can this be done.

Status
Not open for further replies.

Gatorajc

MIS
Mar 1, 2002
423
US
Can the contents of a folder on the server be counted.

For example could you get a count of how many text files are in a folder called mydocuments. If so, how about counting something different than text files.
AJ
I would lose my head if it wasn't attached. [roll1]
 
Use the FileSystemObject to create a Folder object. You can then loop through the File objects associated with the Folder object.

has many good examples of this.

Thanks,

Gabe
 
You could use the FileSystemObject to get a reference to the folder your trying to look at, then loop through all the files in that folder checking the extension against your extension(s). If they one your checking matches than increment a counter. When you are finished with the loop you will have your count of filenames with extension ".whatever".

So basically:

'Create a FileSystemObject
Set fso = Server.CreateObject("Scripting.FileSystemObject")

'Create a reference to the folder in pathname
Set folders = fso.getFolder(Server.Mappath(pathname))

'Get the files collection from the folder
Set files = folders.files

'Define the extensions we planon looking for
Dim extensions, count
extensions = "htm html"

Dim file, types, fn
'Loop through the files collection looking at each file
For each file in files
'Pull out the extension for the file
fn = right(file.name,len(file.name) - InStr(file.name,"."))
'Check if this extension is in the list
If InStr(extensions,fn) > 0 Then
'Increment the count
count = count + 1
End If
Next


This will count all of the extensions that exist in your extensions list as a group, so your total in this case would be all the files with .html or .htm ionstead of individual totals, I'll leave that part up to you :)

Hope this helps,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top