Feb 09 2010

ASP Function to count files in a folder

Category: Aspadmin @ 9:50 am

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
  • Share/Bookmark

Tags: , , ,


Feb 02 2010

Recursive remove directory (RMDIR) in PHP

Category: Phpadmin @ 4:46 pm

This small php function is a recursive remove directory that remove non empty dirs recursively. It enters every directory, removes every file starting from the given path.

function rmdir_recurse($path) {
	$path = rtrim($path, '/').'/';
	$handle = opendir($path);
	while(false !== ($file = readdir($handle))) {
		if($file != '.' and $file != '..' ) {
			$fullpath = $path.$file;
			if(is_dir($fullpath)) rmdir_recurse($fullpath); else unlink($fullpath);
		}
	}
	closedir($handle);
	rmdir($path);
}
  • Share/Bookmark

Tags: , , ,