ASP Function to count files in a folder

/ Published in: ASP
Save to your folder(s)

This ASP function counts files of a specified extension inside a folder: this is done by creating a file system object, open folder and scan files for matching the extension. The match of the extension is made without regular expression but using string functions: Right, Len and Ucase.

Copy this code and paste it in your HTML
  1. Function countFiles(path,ext)
  2. Dim fs, folder, c
  3. c = 0
  4. Set fs = CreateObject("Scripting.FileSystemObject")
  5. Set folder = fs.GetFolder(path)
  6. For Each item In folder.Files
  7. If UCase(Right(item.Name, Len (ext))) = UCase(ext)) Then c=c+1
  8. Next
  9. countFiles = c
  10. End Function


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.