Monday, November 08, 2010 at 12:02 AM.


on maxFolderSize (folder, maxmegs) {
		<<8/10/08; 2:14:04 PM by DW
			<<Scan the folder, adding up the sizes of all the files. If it uses more space than is allowed by "maxmegs" then delete files until its within range. Files are deleted based on age, keep the newest, delete the oldest.
				<<We do math with floating point numbers because the folders can easily overflow 31 bits in size.
	local (f, array, filesize, ctmegs = 0.0, onemeg = 1024.0 * 1024.0);
	new (tabletype, @array);
	fileloop (f in folder, infinity) {
		filesize = file.size (f);
		ctmegs = ctmegs + (double (filesize) / onemeg);
		<<msg (ctmegs)
		array.[f] = file.modified (f)}; //this array will be sorted by mod date, if needed
	if ctmegs > maxmegs { //we have to delete some files
		local (oldtarget = target.set (@array), adr, f);
		table.sortby ("Value");
		target.set (oldtarget);
		<<scratchpad.array = array
		for adr in @array {
			f = nameof (adr^);
			ctmegs = ctmegs - (double (file.size (f)) / onemeg);
			file.delete (f);
			<<msg (ctmegs)
			if ctmegs <= maxmegs {
<<bundle //test code
	<<maxfoldersize ("Ohio:testfolder:", 250) //250MB

This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.