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…

Febbraio 9, 2010

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.

Function countFiles(path,ext)
	Dim fs, folder, c
	c = 0
	Set fs = CreateObject("Scripting.FileSystemObject")
	Set folder = fs.GetFolder(path)
	For Each item In folder.Files
		If UCase(Right(item.Name, Len (ext))) = UCase(ext)) Then c=c+1
	Next
	countFiles = c
End Function

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Comments on “ASP Function to count files in a folder”

One thought

  1. Darren Varndell ha detto:

    Great snippet, except it does not work. There is a syntax error within the IF statement with one too many closing brackets…

    UCase(ext)) Then c=c+1
    should read:
    UCase(ext) Then c=c+1

Comments are closed

Recommended

Calculate dir size recursively with PHP (and count files)

This small PHP function lets you calculate the dir size entering each sub dir and making the sum of the…

Febbraio 1, 2010

ASP equivalent to PHP strip_tags

I’ve found those functions around in the internet and I put them here just to remind how to strip tags…

Febbraio 9, 2010

Recursive remove directory (RMDIR) in PHP

This small php function is a recursive remove directory that remove non empty dirs recursively. It enters every directory, removes…

Febbraio 2, 2010

ASP web bot that get exchange rates

Thanks to Bank of Italy (Banca d’Italia), there are free exchange rates data that are easy to retrieve and parse,…

Dicembre 23, 2009

ASP equivalent to PHP Ucfirst function

This code does the same thing that Ucfirst function makes in PHP. “Ucfirst” means “Uppercase first letter”. ASP doesn’t have…

Novembre 10, 2009

ASP equivalent to PHP ereg_replace function

I’ve used so many time the php function ereg_replace that when I have to use ASP (‘cause sometimens you have…