Label Filter - Empty Folders & Partial Temp Files In That Folder

Hello,

Right now I Have a Label Filter that labels all empty folders:

Sometimes when a folder is empty but a new file is being downloaded to that folder (not empty anymore), I would still like that folder to be considered empty but only if it contains files that end with an extension .part

I've been trying to create this myself but I keep failing (I did disabled my first working Label Filter so it wouldn't interfer).

Could I get some help on how to build this Label Filter rule?

You could do that using a script column which returns true or false for each folder after looking to see what's inside it. The column would then be available to use in filters.

I'm glad I wasn't writing the clauses wrong then, I guess. It's not that big of a deal for me to have this working, so if a script needs to be written in order for this to work, then I'll pass.

Thanks for responding, Leo.

Scripts are easy :slight_smile: This will add a column called EmptyDirExceptPart that you can then use in your filter (it will equal 1 when empty, and ignores .part files). Save the script to your /dopusdata/Script AddIns folder with a .js suffix.

// Called by Directory Opus to initialize the script
function OnInit(initData)
{
	initData.name = "EmptyDirExceptPart";
	initData.version = "1.0";
	initData.copyright = "(c) 2017 jpotter";
//	initData.url = "https://resource.dopus.com/viewforum.php?f=35";
	initData.desc = "";
	initData.default_enable = true;
	initData.min_version = "12.0";

	var col = initData.AddColumn();
	col.name = "EmptyDirExceptPart";
	col.method = "OnEmptyDirExceptPart";
	col.label = "EmptyDirExceptPart";
	col.justify = "left";
	col.autogroup = true;
}

// Implement the EmptyDirExceptPart column
function OnEmptyDirExceptPart(scriptColData)
{
	if (!scriptColData.item.is_dir) return;
	var readDir = DOpus.FSUtil.ReadDir(scriptColData.item);
	while (!readDir.complete) {
		var item = readDir.Next()
		if (item.is_dir || item.ext != ".part")
		{
			scriptColData.value = "0";
			return;
		}
	}
	scriptColData.value = "1";
}
1 Like

Writing a script from scratch, I would say is easy for programmers, that of which, I am not :slight_smile:

That was easy. At first, I had no idea how to even use it in a filter. Took 1 minute and it worked :slight_smile:

Thank you, Jon, for writing the script part. It's nice to see empty folders with partial downloaded files in it still marked as empty.

To be honest, when Leo said a script column, I thought a column would have to be active in order for it to work.

Thank you both ( :opusjon: & :opusleo:) for always taking the time to write scripts for your users!

No problem!

In the future we're considering adding a way to write filter scripts directly rather than having to go via a column, but at the moment this is the best way to extend the searching/filtering capabilities and as you've discovered, the column doesn't actually have to be displayed to be able to filter on it.

1 Like

Ran into a few quirks if there are sub folders and also when I try and delete the main folder (a second prompt asking for administrator permissions is asked before it can delete the folder).

Examples:

One empty folder with no files or folders inside, everything looks and deletes fine.

This Label Filter is active:

Still using the same Label Filter as above, if you add an empty folder inside the test folder, the 1st folder isn't marked as empty but the second (inside) folder is.

If I try and delete the main folder, it says "You'll need to provide administrator permission to delete this folder". I click Continue and the folder is deleted.

With the above scenario, if I use this Label Filter:

The main folder (and sub folder) is correctly marked as empty

and, I don't receive the delete needing administrator permissions.

If I turn off the Script Column part in the Label Filter, the Main Folder and 2nd Folder gets correctly labeled.

I don't mind having it all turned on, just wanted to make sure others are aware of what could happen. Maybe something inside Opus or the script needs to be changed?

Thanks.

The script is looking for either a sub-folder or a non-.part file to test whether the folder is empty or not. If you want it to ignore sub-folders altogether, that's easy - take out the "is_dir" test:

	if (/*item.is_dir ||*/ item.ext != ".part")
	{
		scriptColData.value = "0";
		return;
	}

Be aware though that that will ignore sub-folders completely, even if they have something in them. I'm not sure exactly what criteria you want to use for this.

If you add readDir.Close(); to the bottom of the script it should fix the access denied error.

...
    }
    readDir.Close();
    scriptColData.value = "1";
}