Advanced Rename Improvement: Move To Base Dir and Move Additional Files

(Edit: this initiated as a feature request, but later I became aware that I could implement it on a script, so I did it and cancelled the request.)

The program MusicBrainz Picard has two renaming options that I liked, but that program works only for music.

They are:

  1. when renaming, move files to an user specified base directory...
  2. and move additional files together.

Old name is Artist - Title.mp3;
Full path is C:\Music\Artist - Title.mp3;
New name is {Artist}\{Track Number} - {Title}.mp3 (replace these with the correct shortcodes);
User defined base directory is D:\;
Final name becomes D:\Artist\1 - Title.mp3 (replace these with the correct embedded metadata);
There was the additional file C:\Music\Cover.jpg;
User defined that *.jpg should be moved together.
The additional file becomes D:\Artist\Cover.jpg (same level of the file);

If possible, I would like to have relative reference for the additional files.

There was the additional file C:\Cover.jpg;
User defined that ..\*.jpg should be moved together (one level above the file).
The additional file becomes D:\Cover.jpg (same relative level to the file);

And also support for moving folders as additional files.

User defined that ..\License\ should be moved together.
The additional folder becomes D:\License\ (including everything bellow);

The GUI could include new fields to let the user define the base directory and the additional files filter. The RENAME command should also include new parameters for these. For the additional files filter, instead of a string, an Opus filter could be used (saved or a new one).

With that, I could, for example, create a button that opened the "Edit Metadata" dialog, then, when it closed, applied a rename to the file as to reflect any metadata changes on the file system.

e.g. a script button capable of identifying the file group of the file and setting the rename parameters accordingly - if the file is a movie, set base directory as D:\Movies, else if a picture, set as D:\Picture.

If this were implemented, I think I would not need the OnAfterRename event (as suggested on its thread). With the OnAfterRename event I would try to implement this. The OnAfterRename would have the advantage of being triggered by the inline rename also, but that is not too important to me.

You can already move things around by specifying paths (relative or absolute) as part of the new name.

For the second thing, moving other random files in the same folder, is the aim to move/rename the files or the parent folder they are in (or both)? A rename script could probably do either or both.

Oh, I had tried that on the RegEx mode and was unable to input :, so I guessed absolute path was not supported, but now that you said, I tried on the standard mode and it seems to work.

Do you refer to the OnGetNewName function? Can it only have side effects if the file is indeed renamed? I got the impression that using it would trigger side effects even for files that did not match the old name. Maybe I misunderstood it.

Yes, OnGetNewName.

It sounds like you want to rename the folders the files are in, based on the files inside them. A rename script can do that.

I made a first draft of the script using OnGetNewName. (1.9 KB)

It seems that I won't be able to use it with the Advanced Rename dialog, because the script has side-effects (moving related files) and these are triggered by simple opening the AR dialog or previewing the new names.

The same old warning in this thread about side-effects still applies.

The alternative is to move the way of defining the new name to the script and use it in a button. I think that is a bit more tiresome, as keyword codes can't be used there and I can't quickly apply a one-time substitution. Not pretty, but can be done.

Ideally, the rename presets would be able to save the user defined paths and filters and the side-effects would not kick unless the user decided to apply the rename.

Do you need to move individual files and leave others behind, or do you need to move the whole directory and all files within it?

Move files or folders, siblings (same level) or uncles/aunts (one level up - at least for now, but better have unlimited support, as on my draft).

As I expect to use that function in folders with a standard structure (known to me), most of the time everything will move and any left-over will be inspected and probably deleted as unwanted. Empty left-over folders on the old path will be deleted. For my case, all file access permission will be inherited from the root, so copying permissions is not necessary.

That seems very complicated, if sometimes you move the folder, and sometimes you only move the files.

Are you sure it makes sense to do everything in a single rename operation? Splitting it up into two, one to sort out the files, another to sort out the folders, might make sense.

Of course, you can do just about anything with a script, it's just a matter of how complex you want to make things. The issue with side-effects can be worked around by making the script ignore the files which would have been already been moved when their parent folders were processed, for example. But it may be a lot easier to split things into two instead of trying to do everything at once.

The best approach will depend on the complete and precise details of everything you want the rename(s) to do.

I think of it like this: its a rename of a leaf that triggers the rename of leafs and branches above or at the same level.

I am not sure about how to do that splitting without something like an OnAfterRename event. With it would be easy, as the OnGetNewName would take care of the main file and the OnAfterRename of the related files.

I just found the "getNewNameData.custom" that I ignored before. It looks very helpful for what I need. Does the rename preset also saves data the user wrote on these custom fields? (Edit: seems like it does, per another thread. For curiosity, I tried to search the release notes to discover when that option was included, but failed. Edit 2: found it - added on Opus 12, as per the PDF release notes.)

I removed the feature-request tag, as I am writing a script to fulfill what I described. The talk was helpful to make me realize that I could do it with what Opus already offers.

I will be using buttons to trigger the rename to avoid the rename window triggering side-effects before the user has committed the rename of the main file. This has some downsides, but is manageable.