I have the following command in a function to clear up backup files from the current folder. Does anyone know if there's a parameter that I can use to run this command recursively - i.e. to remove the files from any subfolders as well as the current folder?
I think you forgot to include the command.
Delete is usually recursive by default.
Oops! This is the command:
cmd.RunCommand "delete *.rpp-bak /NORECYCLE"
It currently doesn't delete files from subfolders.
The command you want is:
Delete NORECYCLE FILTERDEF name match *.rpp-bak
So, if you're using VBScript:
cmd.RunCommand "Delete NORECYCLE FILTERDEF name match *.rpp-bak"
(Assuming the location(s) you want to delete from are already selected in the cmd object.)
Thanks for your reply. When I run:
cmd.RunCommand "Delete NORECYCLE FILTERDEF name match *.rpp-bak"
It also seems to attempt to delete all files with an .rpp extension - I only want *.rpp-bak files to be deleted.
????
The message I'm getting is more specific - it is planning to delete a file that I really need to keep! -
...although when I pressed the Delete button it actually didn't delete any files (.rpp or .rpp-bak)
The message implies that's the only file selected in the command object (which will then be skipped by the filter).
TBH I don't know what should or shouldn't be selected before I run this command. If I select nothing (i.e. click on a blank space), then nothing gets deleted. If I click on a specific file or folder, then whatever I select will get deleted. The *.rpp-bak filter seems to be ignored completely.
I guess I am misunderstanding how this is intended to work?
You should select the folder(s) which contains the files you want to delete.
If I do that the selected folder itself gets deleted (along with all of its contents). Again, the filter is being ignored completely.
Could you share the whole VB Script you're using ?
Here's the full script:
Option Explicit
Function OnClick(ByRef clickData)
DOpus.ClearOutput
Dim cmd
Set cmd = clickData.func.command
cmd.RunCommand "Delete NORECYCLE FILTERDEF name match *.rpp-bak"
End Function
Works fine here.
Before (only Folder1 and Folder2 are selected before launch) :
During : Warning message asking for confirmation (stating the content to be deleted might be affected by a filter) :
Afer confirmation :
Only the "*.rpp-bak" files in selected folders (Folder1 & Folder2) are being deleted : not the files in these folders with other extensions, not the files in non selected folders.
EDIT : You have to select something. You are using the Command object provided by clickData to execute your command, and it will only act on files/folders that are selected prior to the button click (as they are already added to the files property of the Command object).
OK this is my equivalent. It removes the folder(s) selected along with its contents. Is that the intended behaviour (i.e. to delete the folder, even though its name does not match the filter)?
Before:
During: message when I click the button to execute the function:
After:the Backups folder has been deleted:
No it's not. Look closer to my "after" screenshot, the folders Folder1
and Folder2
which were initialy selected are still there.
They are just missing the ".rpp-bak" files that have been deleted.
No.
I don't know why you have this behaviour and I can't reproduce it.
The code you copied before is the only code in the button you're clicking on to execute this function ?
EDIT : I just made a test, where one of the folders would only contain .rpp-bak
files and in that case, it also gets deleted.
@Leo : Is it the expected behaviour ?
@itm : Are you in that situation where your Backups
folder only contains *.rpp-bak
files (which could be understandable considering its name) ?
Some of my folders contain a combination of *.rpp-bak and other file types. If I run the script against those folders it will only delete the folder if it consisted only of *.rpp-bak file - i.e. if the delete operation left the folder empty.
OK, so we have the same behaviour. Let's wait for the time Leo can have a look at it to tell us if it's the expected behaviour (I would tend to say it's not ...).
Whatever his feedback, this looks far less annoying as I thought : at least, it does not entirely delete a folder containing files that are not matching the request (in other words, you may be loosing empty folders, which is not annoying and different from your need, but you're not loosing files, which would be critical).
From the top of my head, the only other way I would see would be to script the whole search of matching files and delete them (some recursive dir search with DOpus.FSUtil.ReadDir
for every selected folder, parsing every item to match !is_dir
and ext==".rpp-bak"
. Then add all these files in a delete command).
I think the filter only applies to what's in selected subdirs, with any files/folders explicitly selected being deleted regardless of the filter (unless it can't be deleted, because there are still things under it which weren't filtered out), so that makes sense.
That's what I would do if the default behavior is a problem. Should only require a few lines of code.