Using Multiple Script Methods

Advanced Renamer forum
#1 : 24/12-21 01:29
John Grant
John Grant
Posts: 1
Hello!

I am having trouble using multiple script methods, or one script method + one non-script method.

When I have these methods:

+ 1 : Replace
+ 2 : Script

Where "+ 2 : Script":

function(index, item) {
name = item.newBasename;
// name.replace ... etc.
return name;

The effects of the "+ 1 : Replace" operation are lost. Only the "+ 2 : Script" operations persist.

The same thing happens these methods:

+ 1 : Script
+ 2 : Script

The effects of the "+ 1 : Script" operations are lost, and the "+ 2 : Script" operations persist.

Not surprising, maybe, given the attribute's moniker: "newBasename".

However, replacing "newBasename" with "newName" creates problems.

The "+ 2 : Script" operation now adds extra string bits to the filename.

Even if "+ 2 : Script" doesn't actually do anything:

function(index, item) {
name = item.newName;
return name;

Results:

Foldername: "_test. it's a date [one] mix"
New Foldername: "_test. it's a date [one] mix. it's a date [one] mix"

Questions:

Is it possible to use non-script + script methods?
Is it possible to use multiple script methods?
Should I be operating on the "newBasename" or "newName" attributes?

Thanks.


24/12-21 01:29 - edited 24/12-21 07:32
#2 : 24/12-21 12:34
David Lee
David Lee
Posts: 1125
Reply to #1:
Short answer - try selecting "Apply to Name and extension" and "item.newName" when renaming folders.

First a clarification.

Assume that you are renaming files and your original filename is "filename.ext" in the folder "C:\Users\me\myfiles" and you have inserted a New Name method that changes the filename to "newFilename.newExt"

Now in a subsequent Script method...

item.filename will return the original filename without extension but including the entire path: "C:\Users\me\myfiles\filename"

item.name will return the original filename without extension: "filename"

item.newName will return the latest new filename (ie as defined by any previous methods) including the extension: "newFilename.newExt"

item.newBasename will return the latest new filename (ie as defined by any previous methods) but without the extension: "newFilename"

If you return this value then what will happen when you run the Script will depend on which "Apply to" option you have selected - ie whether it will replace the filename, the extension or both.

The confusion arises when you have a dot within a filename. Windows will identify the end-most dot as an extension separator but any previous dot in the filename will be treated as plain-text. If you were to delete the extension in "my.file.txt" then the new name obviously would be "my.file" however Windows will now identify this as a file named "my" with the extension ".file"

The situation is more complicated with folders since folders do not have extensions. Kim has covered this in his "normal" renaming methods and the "apply to" setting has no effect ie the method will always work on the entire folder name irrespective of any dots.

However this safeguard is not included in the Script method and folder names are treated in exactly the same way as ordinary files and it is up to the user to avoid these ambiguities.

Thus in your example. - Foldername: "_test. it's a date [one] mix" - the script will treat "_test" as the "name" and ". it's a date [one] mix" as the "extension".

"item.newName" will return "_test. it's a date [one] mix" and if you select "Apply to Name" then the Script method will replace only the "name" part of the filename, leaving the "extension" part unaffected - hence it will return "_test. it's a date [one] mix. it's a date [one] mix", as you reported.

Selecting "Apply to Name and extension" would replace the entire name - ie leave it unchanged in this case.

If you were to use "item.newBasename" then the Script would return just the "name" part - ie "_test " and selecting "Apply to: Name" would return return the original name but "Apply to Name and extension" would now return simply "_test ".

"item.name" would behave similarly but since this works on the original name the results of any previous methods will be ignored.

Using "." within filenames is always dangerous and should be avoided.




24/12-21 12:34 - edited 24/12-21 12:50