How to make a button that deletes all in a folder except video file

I get lost in the Help file on this one. What I'd like to be able to do is to enter a folder, then click a button that will select all files in the folder except a video file ( .mkv, .avi, .mp4), and then delete those files, leaving just the video file remaining.

I can't seem to figure out the command for that. I get as far as @select but get bogged down after that one....

As a general rule, use the Select command to select things in the file display for you to look at or do things to, but avoid multi-line commands that change the file display's selection with the intent of changing what later commands in the same batch operation work on. You can pass wildcards and filters to most commands directly, without having to change the file selection, and you'll avoid a few problems if you do.

This will delete all files and folders below the current folder, except ones whose names end in *.mkv, *.mp4 or *.avi.

Delete ~(*.(mkv|mp4|avi))

If you want it to avoid deleting folders, using a Filter is probably the easiest way. You can specify a filter with the FILTER argument, or build/select one interactively by turning on the Delete Filter before clicking the Delete button.

Since you're deleting things, be sure to test what happens in a test folder, not your real ones, in case it deletes something you don't expect it to.

You could also just have a button which selects all the non-video files, where you can then examine what is selected to ensure it is correct before pushing the normal Delete button. That might be a bit safer.

Select ~(*.(mkv|mp4|avi)) DESELECTNOMATCH

Both of those work very well, thank you! So, from your examples, am I to understand that the ~ sign stands for 'all except' ?

See here: https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Pattern_Matching_Syntax.htm

I appreciate it! I would have never dug that out of the Help file, I don't believe. I'll go read up on pattern matching and see if I can get a handle on it.

This is a good candidate for File Type Groups. Instead of listing all of the extensions, DOpus has built in groups for some common file types (movies, music and so on).

This will do the same as @Leo's command.
select ~(grp:Movies) DESELECTNOMATCH

That might be the way I want to go, then. That way if there are any other video extensions that I didn't include in the button, the movie group should cover that.

Quick question: How does Opus determine if a file is a movie??

The pattern matching page I linked to above talks about the grp:... syntax and links to the page on File Type Groups, which wowbagger also linked to above. Have a read of those, and the other pages in the same File Types section, and you should find all you need there.

It looks as if I'll need to do that right away, because that command of "select ~(grp:Movies) DESELECTNOMATCH" does not work for me. It selects everything in the folder, including the video file. No matter if it's an .avi or .mkv or .mp4.

Something must be messed up with my movie file type group. I'm on my way to check it out..

UPDATE: yes, that was the problem. I had to add the .avi and .mkv and .mp4 into the group, and then that code worked. I wonder why they weren't in the group as default in the first place. Not a biggie, just curious. Well, it works now, and I have a lot of reading and studying to do with those linked pages, so here I go...

The default Movies grup includes these extensions. Maybe you modified it at some point...?

Not that I recall. I just did a clean install of Opus 12 yesterday, after running the trial version for about a week. I don't remember doing anything to any of the group settings. I haven't gotten that far in my 'self education'.

Oh a thought just occurred to me. I have been using Opus in it's various versions for the last 10 years or so. And my normal way to set up a new version of Opus is to install it, then import the settings backup file from the previous version. I do this so that the lister setup and custom toolbars and buttons get installed. So, that could have carried something over that I have forgotten all about. Yep, that's got to be it. Well, it's back the way it should be now.