Saturday, November 27, 2010 at 10:00 PM.


on sizeFolderStructure (folder, adroutline) {
		<<11/27/10; 5:59:50 PM by DW
			<<I always wondered where all the files were in a huge folder, like the one that stores all the static files for This script walks the folder structure recursively, and on each folder tells you how many files it contains, at all levels, and how much space they occupy. That way you can quickly zoom in on where the big stuff is. 
	bundle { //set up outline
		new (outlinetype, adroutline);
		target.set (adroutline);
		op.setlinetext (file.filefrompath (folder));
		edit (adroutline)};
	on dofolder (folder, adrdata=nil) {
		local (f, dir = right);
		if adrdata != nil {
			new (tabletype, adrdata);
			adrdata^.ctfiles = 0;
			adrdata^.size = 0};
		fileloop (f in folder) {
			if file.isfolder (f) {
				local (data, fname = file.filefrompath (f));
				op.insert (fname, dir); dir = down;
				dofolder (f, @data);
				op.setlinetext (fname + " (" + string.gigabytestring (data.size) + " -- " + string.addcommas (data.ctfiles) + ")");
				if adrdata != nil {
					adrdata^.ctfiles = adrdata^.ctfiles + data.ctfiles;
					adrdata^.size = adrdata^.size + data.size}}
			else {
				if adrdata != nil {
					adrdata^.size = adrdata^.size + file.size (f)}}};
		if dir == down {
			op.go (left, 1);
			op.collapse ()}};
	dofolder (folder)};
bundle { //test code
	sizeFolderStructure ("Ohio:Server Backups:static", @scratchpad.folderstructure)}

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.