Label Assignment using Label Filters and contained subfolders

Hi,

Is it possible to assign Labels to folders based upon the names of files/folders it contains? What I'd like to achieve is to change the folder icons for folders that are git repositories (that is, they contain a subfolder named .git).

I've tried using Subfolder but after reading the help I realized that's not exactly what I need here.

You can do it using a Script Column which checks if a .git folder exists beneath the folder it is asked about:

2020-08-04 15-20-39 Clipboard Image

And then use that in the label via the Script Column clause:

You might also want to add a clause before that which restricts the test to folders below a certain drive or path, if you know all your Git repo folders will be in one place (but also have other things there that aren't repos; else you could use a simple path wildcard). That way the script column will not be called on every folder everywhere, which would add some overhead after every folder change.

Here is the script:

Drag it to Preferences / Toolbars / Scripts to install it.

Script code for reference:

function OnInit(initData)
{
	initData.name = "Git Repo Column";
	initData.version = "1.0";
	initData.copyright = "(c) 2020 Leo Davidson";
	initData.url = "https://resource.dopus.com/t/label-assignment-using-label-filters-and-contained-subfolders/36311";
	initData.desc = "Indicates if a folder contains a .git sub-folder.";
	initData.default_enable = true;
	initData.min_version = "12.21";

	var col = initData.AddColumn();
	col.name = "GitRepo";
	col.method = "OnColumn";
	col.label = "Git Repo";
	col.justify = "left";
	col.autogroup = true;
}

function OnColumn(scriptColData)
{
	if (!scriptColData.item.is_dir)
	{
		return;
	}

	var resPath = DOpus.FSUtil.Resolve(scriptColData.item.realpath);

	if (DOpus.FSUtil.Exists(resPath + "\\.git"))
	{
		scriptColData.value = "Yes";
		scriptColData.sort = 0; // Sort Yes before No.
	}
	else
	{
		scriptColData.value = "No";
		scriptColData.sort = 1; // Sort Yes before No.
	}
}
2 Likes

That's brilliant, Leo, thank you very much!

1 Like