Posted By

ginoplusio on 02/09/10


Tagged

ucaserightfilefolderdirfilesystemobject


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

ginoplusio
benrudolph
wizard04
asifrizvigmailcom


ASP Function to count files in a folder


 / Published in: ASP
 

URL: http://www.barattalo.it/2010/02/09/asp-function-to-count-files-in-a-folder/

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.

  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  

You need to login to post a comment.