Filtered Delete command

My first time trying to assign a command to a button. Here's my command...

DELETE "g:\appmydata\email*" FILTER OlderThan7Days RECYCLE

The email folder contain copies of Thunderbird email backups (approx 500MB each). It's cumbersome to delete old folders so I thought doing it via a button click would be a great improvement.

The files in the folder "old" folders are deleted but the folders and subfolders remain. The filter "OldThan7Days" defined in Preferences is where Created Date, NO MATCH, Within 13 days
AND Name NO MATCH, *.ldif (using wildcards)

It essentially works except the folders are left behind. What do I need so the folders get deleted and not just the files?

Thank you in advance for the help.

P.S. If I used 2 commands (SELECT...... and COPY....) as the Standard Function will the COPY get fed the results of the SELECT?

Any ideas on how to change the command/script to get the filtered email folders and sub-folders automatically deleted along with the files?

Is the aim to:

  • Delete all empty folders
  • Delete only the folders made empty by deleting the files (leaving other folders that were already empty)
  • Delete all (empty?) folders with dates older than 7 days (note: unreliable as folder dates are often not meaningful)
  • Something slightly different?

I use a Thunderbird extension to backup all of Thunderbird but it doesn't allow for limiting the number of backup generations to keep. That's essentially what I'm trying to accomplish. A backup folder is generated each day typically. My attempt was to find the backup folders that are MORE THAN n days old and delete them. (An improved approach would be to keep the n most recent - regardless of date - and delete the rest.) So far the folders are targeted correctly by the command and the files within them get deleted but the impacted backup folders (though empty of files) remain along with their sub-folders. If a backup folder is targeted, it should totally disappear.

Thank you for the help.

As a first step I would try if the folders you are targeting are actually affected by the filter you are using.
So maybe run a find with your filter in place, check if the folders are in the find result. If not, then I guess it's quite clear why the delete command will not delete them. If your folders are within the filter-search result, we are back to start, but it's a bit clearer where the fault is - I assume.

Thanks, first, keeping n backup generations became more and more appealing compared to deleting by date which could leave me with no backups if none had taken place recently. So I changed my approach to using a script (first time) to have finer control. Great success with it. And with this I know a minimum number of generations will remain.

But I wanted to give some feedback about the original approach since something doesn't seem right with using the filter by command and targeting folders. With some further testing, my filter is now...

Created Date No Matches within 7 days AND Type Matches [Folders Only]

From the lister, if I type Ctrl-S, pick that filter and Apply, it works fine. But using a button with the following command...

DELETE "g:\appmydata\email*" FILTER "OlderThan7Days" RECYCLE

It does nothing. Right now the folders that should be deleted remain and the files inside them remain.

I thought I'd try changing the filter to where Type Matches [Files Only] and run the command. A file in the target folder was deleted as expected. However, a file located inside a subfolder matching the date constraint (the file also matched the date constraint) was also deleted while the subfolder remained. I didn't expect it to reach into subfolders to delete files so not sure if that is intended. I hope that makes sense.

Up until now I haven't done anything with scripts or commands but I do have a programming background. It might be something I'm doing but something does seem odd about targeting folders. But I'm good with the script solution I crafted, actually I've put together several. Very handy. If you have any questions, please let me know.