Is there a test for an empty library?

I want to write a non-script DOpus button as follows:

If a certain library is empty,
Do something.
If it is not empty,
Do something else.

Is there a non-script test as to whether a library or directory is empty?

You'd need to use scripting for something like that.

Thanks, @Jon. I did my due diligence searching, but it's good to be sure.

Could I suggest that a command modifier along the lines of:
be added. From the posts that I read, others may also appreciate this.


What do you & others want to do based on whether a library is empty or not?

Why avoid scripting for this? If you’re already doing conditional logic, scripting will probably make things easier not harder.

Is there an object in the script to get a file list of all folders including subfolders? Sometimes I need to judge whether a folder is empty based on the files in it. Also for folders without files, the way I know is to enumerate each folder, which makes scripting not easy.

Yes, see the default script for an example. It’s built into the program and shown when you make a new script button.

@Leo, good question. I'll give one example.

I have a number of Sandboxie sandboxes, so that my downloads go into sandboxes and may need to be rescued later. I always download to D: drive (in a sandbox), because the masses of files needed by the browser are copied into the sandbox copy of C: drive.

I created a library that contains the D: drive copies of all the sandboxes, and hence all the downloads that I may want to keep.

Now I want to insert the command modifier conditional:
into my cleanup button commands, and into my shutdown and restart button commands (some sandboxes are on a ramdrive), to warn me if I may have forgotten about recovering downloads.

I can write scripts, but that seems overkill when a straightforward command modifier would do the trick. It looks as if it can be done on the model of

I don't know if it pertains in this case, but there are reasonable answers to that question along the lines of "Because I don't know how to write scripts", "I don't know any scripting language" and so forth.

If you’re already doing conditional logic and branching paths, you either know how to write scripts or can learn in a few minutes, as that’s most of the way there. :slight_smile:

We might add a way to do an empty folder check in non-script buttons for convenience, but that’ll take time. Scripting can do it right now, and will make everything else easier as well (showing an error message etc. if the path is empty).

No, not really. :wink:

@Jon and @Leo, the general test for whether a folder is empty is a doddle. You have a script addin command TestEmpty, with a single argument Target/K for the folder that is being tested, and write

function onTestEmpty (scriptCmdData) {
var oArgs = scriptCmdData.func.args;
var sTarget = oArgs.Target;
var oEnum = DOpus.FSUtil.ReadDir(sTarget);
var bNonEmpty = !oEnum.complete;

That script addin solves the problem for any folder. But the problem remains how to communicate the result of this script back to a variety of buttons that may rely on it. Hence the request for a command modifier.

Without this, my best solution would be writing a temporary file, then the button can test for its existence using @ifexists. But that seems a really clumsy solution.

From a mathematician's point of view, scripting is far more complicated than conditional logic and branching paths. Mathematicians can do conditionals, branching paths, and contradictions, in their sleep — once you understand them, these things are trivial, and you make up the mathematics as you go along. But computing requires that you know stuff — codes and languages and whatever. And this particular problem of communication between scripts and buttons just doesn't happen in mathematics because you make up the spot what you need to move, for example, between geometry and algebra. I know very well that it all goes back to training, but I thought it was worth stating a different point of view.

What I hope, however, is that I am missing some very simple way to communicate the universal script's result across to the various buttons. Perhaps temporary files is the best way.

You could set a variable, but why not just do everything in scripts? At least for now. We'll add something to make this easier outside of scripts in the future, but you can already do everything you want easily if you stop avoiding JScript. :smiley:

That wouldn't work because all the @if... stuff in a non-script button is evaluated before the button runs any commands. You'd be testing if the temp file existed before the command started.

You need to know things in either case.

A lot more people already know JScript/Javascript than any of the bespoke branching and conditional logic stuff we've added to the non-scripting commands syntax.

Using scripting for this kind of thing will make things easier, not harder. The only downside is a tiny bit more typing (but less typing than we've all done talking about it in this thread :slight_smile: ).

1 Like

Thanks, @Leo. I have now written the full script, which was not very long. Being an amateur, I only realised when writing it out that it is slightly more complicated than I had imagined, because I want to test only for the existence of files, not of directories. This would, of course, complicate the construction of any command modifier, as would the recursion and shell parameters of the ReadDir command.

Once again, thank you @Leo and @Jon for your guidance with the dozens of scripts that I have written for my DOpus configuration. (And nothing like a mathematics vs computing squabble — better than State of Origin.)