Delete does not work with FILTERDEF type

This works as expected:

Select FILTERDEF type match folders

This does not:

Delete FILTERDEF type match folders

A message with the number of folders to be deleted will appear but no folder will actually be deleted. Saving the filter separately won't work either.

Similar commands like

Delete FILTERDEF name match *.zip

work fine.

Does it work if you bypass the recycle bin?

Yes,

Delete NORECYCLE FILTERDEF type match folders

will delete empty folders. Folders that contain folders or files will be skipped.

In that case, I suspect it's a bug in Windows. I've not looked at it for some years but in the past I found filtering deletions doesn't always work with the recycle bin. It can result in a long list of files (not just the top-level selected ones, since they might be filtered out themselves) under different folders being passed to the recycle bin API, and sometimes when you do that it does nothing at all, but returns success.

Yes, this seems to be the explanation. I stumbled upon the bug again.


This should delete all selected files and folders:

Delete FILTERDEF =true

(Not so) surprisingly, it only deletes files.

Modifying the command reveals that the filter apparently only evaluates the first folder and then gives up:

Running this

Delete FILTERDEF =Output(name + " | " + is_dir);true

on

returns

Evaluator:  folder 01 | true
Evaluator:  file 01.txt | false
Evaluator:  file 02.txt | false
Evaluator:  file 03.txt | false
Evaluator:  file 04.txt | false
Evaluator:  file 05.txt | false

Adding NORECYCLE makes the command work as expected.

Delete NORECYCLE FILTERDEF =Output(name + " | " + is_dir);true

Sigh.

1 Like

I think there's a couple of different things going on here which give a confusing result.

Recursive filters are primarily file filters

In the case of operations like delete, recursive filters are file filters. The filter determines for each individual file if it should be deleted or not.

The default behaviour is to recurse into every folder and sub-folder, and then compare each file encountered against the filter, and delete it if it matches.

For folders, the filter is only used to determine whether the operation should recurse into it or not. For a standard filter this is achieved using a Sub folder clause, and for an evaluation filter, the evaluation clause itself determines what the filter is being called for by checking the value of the subfolder variable.

Folders are not compared against the filter to see if they should be deleted. Instead, folders are deleted if they're empty after the recursion is complete.

Differences between recycle and no recycle

This seems to be a bug. With native (non-recycle) delete, any folders that have been selected will be deleted if they're empty once files within the folder have been deleted.

With the recycle bin it seems that folders aren't being deleted even if their contents are. This discrepancy seems like a bug to me, I'm not sure what the underlying reason for it is but the two operations should be consistent, so we'll get that looked at.

Why the evaluator isn't being called for subsequent folders

This is really down to the nature of the filtered operation, which as described above is a file filter. The evaluation clause will be called for all files to see if they match the filter.

For folders, the evaluation clause isn't called to see if they should be deleted - instead, it's called to see if the operation should recurse inside them. The subfolder variable will be set to true when this is the case. Returning false from here lets you stop the operation from recursing into the folder (and returning true allows it).

But if the evaluation clause doesn't actually look at the subfolder variable at all, Opus doesn't bother calling it again for any further subfolders, and instead just proceeds to recurse into them all. This is why in your test you get output for folder 01 but not any of the other folders. If you change your code to output the value of the subfolder variable as well, you'll then see it being called for every folder.

2 Likes