Search for folders with a defined amount of subfolders/files

Hi guys,

Is it possible with the advanced "Find in File" function to search for folders that contain no sub folders or a specified amount of files?

Many thanks for all help.

Kind regards,
Skeeve

It's possible but not easy, unless you're good with scripting.

You use Script Column clauses to call a script column which will be given the name of each item and can then do and return anything it wants (e.g. "Yes" or "No") and the filter can check for results (e.g. Match "Yes").

Opus also provides scripting objects to simplify looking inside of folders (examples).

So all of the pieces are there but require some assembly.

In terms of what's there without using scripting, I think it is limited to checking the total size of a folder, which works but won't differentiate between files directly below the folder and ones in a sub-folder. Everything else is about attributes of the folder itself (name, date, etc.) and not of the folder's contents.

Hi Leo,

Many thanks for your help.

Tried to write such a script, but for some reason the entry point of the script column is not recognized:
05.09.2016 21:08 CheckInvalidSVNFolders.js: Error at line 32, position 5
05.09.2016 21:08 CheckInvalidSVNFolders.js: Das Objekt unterstützt diese Eigenschaft oder Methode nicht. (0x800a01b6)

It's very close to the example script, so I'm really wondering why this isn't working. If anybody have a hint that would be nice:)

For future Dopus updates, just as a suggestion, a huge benefit would be the possibility to access all the pre-defined column variables like

  • File count
  • Sub-folder count
  • Total File count
  • Total Sub-folder count

If we can get access to these in the "Find Files" interface, this would have been done in no time:)

Anyway, thanks a lot.
CheckInvalidSVNFolders.rar (508 Bytes)

[code] var cmd = data.AddColumn();
cmd.name = "CheckSVNFolder";

cmd.method = "OnCheck";
cmd.desc = data.desc;  <-- Error line
cmd.label = "SVN Okay?";[/code]

data.AddColumn returns a ScriptColumn object, and there's no desc property on those. If you remove that line it seems to work.

Hi Leo,

Nice, this is working fine now.

Many thanks for your help! Much appreciated! The error message was somewhat misguiding.

Hi Leo,

Sorry for bringing this up again.

While the script is working fine for most folders, in some cases it returns unpredictable results, especially for folders that are on a very high path level (and have many sub folders).

Each time I refresh the script column, results may change. Usually they only change for the first 2-4 entries. But if the number of subfolders/files gets lower, everything works fine and there is also no error message from scripting system or functions.

So is there something elemental I've missed or doing wrong or is this a problem or restriction with scripting?

I think I'm not doing any extraordinary stuff but it may be something on my side though of course.

Many thanks for all support.

Kind regards

// ************************************************
// Check for invalid object folders by Skeeve


// ************************************************
// Check function
function OnCheck(scriptColData)
{
   	// Proper column?
	if (scriptColData.col != "CheckSVNFolder")
        return;

	// Clear result value (Necessary?)
	scriptColData.value = "";

	// Is this not a folder?
	if (scriptColData.item.is_dir == false)
		return;

	// Sub folders available? This is not an object folder then...
	if (scriptColData.item.metadata.other.dircount > 0)
		return;

	// No files available?
	if (scriptColData.item.metadata.other.filecount == 0)
	{
		// An empty folder is also invalid!
		scriptColData.value = "X";
		return;
	}

	// Access to folder content
	var folder = DOpus.FSUtil.ReadDir(scriptColData.item.realpath, false, false);

	// Folder contains any valid content files?
	var hasContent = false;

	// Check all files for content
	while (folder.complete == false)
	{
		// Get item
		var item = folder.Next();
	
		// Is content file?
		if ((item.ext == ".tga") || (item.ext == ".wav"))
		{
			hasContent = true;
			break;
		}
	}

	// Folder doesn't contain valid content?
	if (hasContent == false)
		scriptColData.value = "X";
}


// ************************************************
// Register
function OnInit(data)
{
	data.name = "Check for invalid SVN object folders";
	data.copyright = "Skeeve";
	data.version = "1.0";
	data.default_enable = true;

	var cmd = data.AddColumn();
    cmd.name = "CheckSVNFolder";
    cmd.autorefresh = true;
    cmd.method = "OnCheck";
    cmd.label = "Invalid?";
}

I would use DOpus.Output to make the script log some information about when it is being called, for which folders and which results it returns. Then you can look at the script log and see where the unexpected behavior is coming from.

e.g. Is the script always being called at the times you expect, and with the parameters it is expecting? If so, are the results it returns correct?

Hi Leo,

This was a very useful hint, thanks. I've added log strings and it turned out that

scriptColData.item.metadata.other.dircount

is causing the trouble.

This returns sometimes 'undefined' and sometimes the correct number of subfolders. In the doc it's stated that this can be used if the sizes for a folder have been calculated but I've been enabled auto size calculation for all folders and even if I force a manual folder size calculation, it sometimes returns 'undefined'?

Is this a bug? Can I avoid the problem or is there an alternative for this value?

Thanks,
Kind regards,
Skeeve

You can't rely on that since it won't always be there.

You would want to count the folder contents yourself. But don't worry, Opus provides some helpers which make this trivial. Example here.

Bingo, Problem solved:) I already was using the FSUtil object so it wasn't a big change.

But out of curiosity, what is this metadata.other object for if you can't rely on it? So you basically shouldn't use this at all? In that case I would recommend to mark this in the doc to prevent other users from running into the same issue.

As always, many thanks for all your competent and fast support Leo!

You can check the Item.got_size property for a folder to see if sizes have been calculated - if so, the other.dircount and associated properties will be available.

Hi Jon,

I see - many thanks for the info.

Kind regards,
Skeeve