Move description into filename

(Split from the original thread, Rename file that is being used.)

That'd make more sense as a separate thread/question, but here's the answer:

Rename PATTERN . TO "* {userdesc}.*" FILEINFO

I modified it a little bit to remove description once added to file name and to prevent button from adding space at the end of file name when there's no description set

Rename PATTERN *.* TO "* {userdesc}.*" FILEINFO SetAttr META comment: Rename PATTERN "(.*) \.(.*)" TO "\1.\2" REGEXP
But the second rename is not performed. Any ideas as to why?

I think part of your problem is this line:

SetAttr META comment:

It sounds like you want to reset the description but you're attempting to reset the comment. The following works for me but I can't seem to get Opus to set a null value for the description without displaying the description dialog box (bug perhaps)? But if you click through the description dialog without entering anything it seems to work.

Rename PATTERN *.* TO "* {userdesc}.*" FILEINFO SetAttr DESCRIPTION = "" Rename PATTERN "(.*)( )\.(.*)#5" TO "\1.\3" REGEXP

This is exactly what I'm trying to do. See here.

Anyway the second rename still doesn't work and DO adds space at the end of file name when no description is set.
If I remove
SetAttr META comment:
then the second rename works ok.

Rename PATTERN *.* TO "* {userdesc}.*" FILEINFO Rename PATTERN "(.*)( )\.(.*)#5" TO "\1.\3" REGEXP SetAttr META comment:
This code on the other hand works ok when no description is set (doesn't add the unnecessary space). When there's description set, it adds it properly but doesn't clear description attribute for the file.

SetAttr DESCRIPTION "xyz" and SetAttr META "comment:xyz" usually do the same thing. (There may be some obscure cases where they do something different but I can't think of any right now.)

The way Opus parses command arguments, giving an empty string is the same as not giving any string at all. So SetAttr DESCRIPTION="" is the same as SetAttr DESCRIPTION and will open the dialog.

We might add a separate SetAttr SETDESCRIPTION command which is like SetAttr DESCRIPTION except that it clears the description if no string (or an empty string) is given to it, instead of opening the dialog. The end result will be the same as using SetAttr META comment: but a bit easier to find in the command editor menus and manual.

We'll look into that but you can work around it by using one Rename instead of two. You can do that using a rename script, like this:

[code]Rename PATTERN . TO "* {userdesc}.*" FILEINFO
SetAttr META comment:

@script vbscript
Option Explicit
Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName)
Dim posExt
posExt = InStrRev(strNewName,".")
If (posExt > 0) Then
posExt = posExt-1
strNewName = Trim(Left(strNewName,posExt)) & Right(strNewName,Len(strNewName)-posExt)
End If
End Function[/code]

This one works as expected. Thanks.
I hope you guys will see what's wrong with the code I made. It seems to be a little messy to use VB to just remove a space. And of course my rename command worked great standalone but not after adding description to file name and clearing description.

We've looked into that and made some changes for a future beta (probably not the very next version) which will enable this to work:

Rename PATTERN *.* TO "* {userdesc}.*" FILEINFO SetAttr META comment: Rename PATTERN "* .*" TO "*.*"

This still doesn't work at the time of writing (although we're thinking about adding a new @modifier to allow it):

Rename PATTERN *.* TO "* {userdesc}.*" FILEINFO Rename PATTERN "* .*" TO "*.*" SetAttr META comment:

The reason the second example still doesn't work (and may never work) is that if a file is not matched by the rename command then it is considered "failed" and will not be passed to subsequent commands. We need to keep that behaviour for buttons that may depend on it, but we might be able to add a @modifier that tells Opus to ignore rename failures and continue to run commands against those files regardless.

Either way, the version with the SetAttr command in the middle will work in the future. But you should also continue using the VBScript version that works already, anyway, because it's more efficient: It will do nothing at all to the file if the file has no description to move, instead of doing two renames just to get back to where you started in that case.

(BTW, I'm using a simple wildcard for the 2nd rename instead of a regexp as in the original examples. There's no reason for that other than that it makes the command more simple. The regexp version will work the same if you want to use regexps instead of wildcards.)

To handle the version of the command with the two renames at the top, we will add a new NOMATCHNOFAIL argument to the Rename command, which tells it not to mark files that don't match the rename pattern as failures. (Failed files are skipped by the rest of the function.)

So something like this will work once we release the update (probably not the very next version) with that new argument:

Rename NOMATCHNOFAIL PATTERN *.* TO "* {userdesc}.*" FILEINFO Rename NOMATCHNOFAIL PATTERN "* .*" TO "*.*" SetAttr META comment:

(Of course, this will now mean if you run the function on a file that doesn't have a . in its name at all, then the file won't be renamed at all and its description will still be cleared. You could fix that by improving the rename patterns to handle both cases, although as before it is still better done using a single rename with a script to handle the logic.)

Thanks for all these replies and the forthcoming new feature. Anyway, why didn't the code with setattr in the middle work before? Some kind of bug?

If the file had no description then the SetAttr command to clear its description realised there was nothing to do and flagged the file as 'failed', which stopped the later commands running on it. We'll change that to a success.

Same deal with the Rename command really; the command didn't apply to the file it was given, so the file was skipped.

The way the Rename command works can be useful at times, and people's existing buttons may depend on it, so we'll add a new argument to let you choose the Rename behaviour. OTOH, SetAttr behaving that way doesn't seem useful, so we'll just change that to consider no-ops a success instead of a failure.