Button help: Delete all - with prompt to exclude based on text

I would like a button that deletes all files+folders in the active folder...except for those that have certain text in their names.

I was hoping this exclusion could be handled via a prompt that asks me to enter the text. It's also important that it look anywhere in the filename.

So for example, if I enter the text "snag"..."snag, snagit.ext, thesnagman, excelsnagsheet.xsl, etc." should be excluded from deletion.

I asked ChatGPT about this, but none of the codes it provided worked in Directory Opus. Hoping you wonderful humans can help me! :slight_smile:

I think this will do what you're asking for:

Delete FILE="~(*{dlgstring|Enter string to exclude:}*)"

I would be very careful using that, though. If you type the wrong thing, it won't be easy to tell what it's about to delete.

(De)Selecting and/or hiding the unmatched files, then deleting as a separate step after visually checking they're the right ones, would be much safer, and what I would do instead.

@Leo I think your last suggestion seems wise.

So I was thinking of using Directory Opus' search bar to filter out excluded files/folders. But I don't know what search syntax to use.

For example...how can I exclude any files/folders that contain "snag" or "pull" in their names?

Note that I want to exclude files/folders that have "snag" or "pull" anywhere in their file names.

For example, a file like "thesnagit.txt" or a folder named "thepulleymachine" should be excluded because they contain the excluded text in-between their names.

In the Filter Bar (wildcards mode), ~(*(snag|pull)*) will do that.

Hi @Leo, while I greatly appreciate the code...I don't think I'll be able to remember and type it out.

But I stumbled across another solution - which I need your help accessing in a faster manner.

So I was playing with the advanced 'Find' (Ctrl+F) panel. By using the "Advanced" tab, I was able to get the exclusions I want.

Now I know you can press 'Save' and call it back up using the "Filter" dropdown.

However, is there a way I can create a toolbar button that calls up this 'Find' panel and automatically loads my "search filter"? And furthermore if it's not too much trouble...when pressing that toolbar button I don't want the actual "Find" search action initiated. It should just show the panel with the search filter loaded...that way I can edit the search terms in the Find box.

The Find command can do that.

See the NOAUTORUN and FILTER arguments.

I'm noticing a quirk of the "Find" tool @Leo

I'm using a button with the following code:
Find ADVANCED=filter:Find-Exclude

It brings up the "Find" panel and loads my search filter "Find-Exclude".

I originally saved this search filter with template-text that is meant to remind me of certain searches or wildcard tips:

Obviously, this template-text gets replaced with whatever text I require for that task. Once my task is complete, I close the Find panel.

The problem is that the next time I use my custom toolbar button to load the Find panel and search filter...it shows me my last search (instead of the template-text):

Notice the word "modified" next to my search filter "Find-Exclude". If I go to the drop-down and click on my filter again...it resets back to the original desired settings and template-text.

But I don't want to have to manually do this every time. Is there a way I can prevent the "Find" panel from remembering the previous search? Maybe something via settings or the changes to the button code?

Try

Find FILTER NAME=Find-Exclude ADVANCED NOAUTORUN IN {sourcepath}
2 Likes

Thank you @lxp and @Leo for the ultimate solution and pushing me in the right direction!

The final code provided by @lxp solves the problem I mentioned earlier. And this is the most noob-friendly method to accomplish what I originally asked for in my original post.

Though @Leo...I noticed the 'Find > Advanced' tool seems hard-coded to include file extensions in the search. When I asked ChatGPT if that behavior could be disabled, the only solution it offered was to use some convoluted "Regular Expression" that I could not understand...and is not really convenient to implement in my use-case.

If possible, I hope the Directory Opus team could include a checkbox option to "ignore file extension". To be clear, I'm referring to the area where you have the three existing checkboxes "Case sensitive", "regular expression", "wildcard".