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…

February 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
	countFiles = c
End Function


I'm a software engineer, an everyday web developer and a maker. I usually build sites with PHP, within or without WordPress. I build Internet of Things with Arduino and ESP8266. I'm the founder of and and I'm actually the Chief Technical Officer of Better Days web agency.

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

One thought

  1. 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


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…

February 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…

February 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…

February 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,…

December 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…

November 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…