Script help: need help finding folders with the largest files size

Here is what I would like to do. I want to get a list of folder sizes (not counting subfolders). I will be using that list to then open new tabs based on the largest 5 folders.

I guess my question is do I have to manually iterate over all the files in the directory and add the size up for each folder or is there a way to just get calcuated size of just the files in the folder excluding sub folders?

Or maybe, is there away to add a column that calculates just the size of the files in the folders, but ignores their sub directories? I have never done anything with custom columns.

Easily done using a script column:

  • SizeChildren.js.txt (1.1 KB)
  • Download it and drop it on the scripts list (Settings > Scripts), or copy it to the /scripts folder/alias.
  • The added column will be under the Script category.

Code for reference (contained in the download above):

function OnInit(initData)
{
	initData.name = "SizeChildren";
	initData.version = "1.0";
	initData.copyright = "(c) 2024 Leo Davidson";
	initData.url = "https://resource.dopus.com/t/script-help-need-help-finding-folders-with-the-largest-files-size/50574";
	initData.desc = "Column showing size of folders, without recursion";
	initData.default_enable = true;
	initData.min_version = "13.0";
}

function OnAddColumns(addColData)
{
	var col = addColData.AddColumn();
	col.name = "SizeChildren";
	col.method = "OnSizeChildren";
	col.label = "Size Children";
	col.type  = "size";
	col.justify = "right";
	col.autogroup = true;
}

function OnSizeChildren(scriptColData)
{
	if (!scriptColData.item.is_dir)
	{
		scriptColData.value = scriptColData.item.size;
		return;
	}

	var totalSize = DOpus.FSUtil.NewFileSize(0);
	var folderEnum = DOpus.FSUtil.ReadDir(scriptColData.item, false);
	while (!folderEnum.complete)
	{
		var folderItem = folderEnum.next;
		if (!folderItem.is_dir)
			totalSize.Add(folderItem.size);
	}
	scriptColData.value = totalSize;
}

thanks very much. I will try this as soon as I can .

This works great! Exactly what I needed. You just save me so much time. Thank you

1 Like