Hey, I'd like to know if you can copy files to a path only if they match a specific extension ? And without deselecting non matching extensions for whole button... so it can run on multiple selected files with different extensions going to different paths.
I could move a selected file to a path only if it matches the extension with this regexp in a button:
Thanks heaps I got it working now! That code didn't quite work but I've been muddling around with it for a while and ended up only needing a slight modification to yours that made it work.
You're right, it wasn't working properly, although it does work sometimes & had always worked for me until I did more thorough testing just now.
I think the RESELECT line is not always selecting what I had expected it to do, with it working sometimes if you happened to have the right selection previously. Maybe it was always like that even in Opus 10.
Here's a better way to do it using Opus 11. The function type should be set to Script Function.
Function OnClick(ByRef ClickData)
ClickData.Func.Command.files.count ' (Workaround for bug in current beta.)
ClickData.Func.Command.RunCommand "Copy TO ""C:\Test\Text Files"" PATTERN *.txt AS *.txt"
ClickData.Func.Command.ClearFailed
ClickData.Func.Command.RunCommand "Copy TO ""C:\Test\Image Files"" PATTERN *.png AS *.png"
ClickData.Func.Command.ClearFailed
End Function
(The ClickData.Func.Command.files.count line at the top is needed in Beta 7 but should no longer be needed after the next update.)
When each Copy command runs, any files that don't match the PATTERN are flagged as "failed", which prevents them from being passed to subsequent commands. Calling ClearFailed on the Command object resets the flag so that both commands consider the full set of files that were selected at the start.
(The last ClearFailed is not entirely redundant, although it is not strictly needed either; it's there to influence which files are left selected after the script completes.)