^ Scripting: renameitem (Bug, Resolved)

Discuss and share scripts and script files...
Post Reply
Zardoz2293
Posts: 616
Joined: 09 Nov 2011 20:20
Location: USA

^ Scripting: renameitem (Bug, Resolved)

Post by Zardoz2293 »

I'm having problems renaming using renameitem with some types of naming conventions for folders and files. All I'm seeking to do is keep the same exact current name for the folder or path and insert a string at the beginning.

Example #1: renameitem( "CHANGED-- *?", $Folder, { 0 | 1 |2 | 3 } );

Desired:

Code: Select all

FROM:
C:\Test\v3.64 (2010-12-10)             <DIR>

TO:
C:\Test\CHANGED-- v3.64 (2010-12-10)   <DIR>
Results: (Missing the period)

Code: Select all

FROM:
C:\Test\v3.64 (2010-12-10)             <DIR>

TO:
C:\Test\CHANGED-- v364 (2010-12-10)    <DIR>

Example #2: renameitem( "CHANGED-- *.?", $Folder, 0 );

Results: (Added period)

Code: Select all

FROM:
C:\Test\v3             <DIR>

TO:
C:\Test\CHANGED-- v3    <DIR>

However, the return value is "C:\Test\CHANGED-- v3." (with a period)

What are your thoughts?
Last edited by Zardoz2293 on 08 Feb 2012 14:08, edited 1 time in total.
MacOS Tahoe v26.5.1
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Scripting: renameitem

Post by Stefan »

Try
renameitem( "CHANGED-- *.?", $Folder);


while
* = original base
. = original period
? = original extension

Zardoz2293
Posts: 616
Joined: 09 Nov 2011 20:20
Location: USA

Re: Scripting: renameitem

Post by Zardoz2293 »

Stefan wrote:Try
renameitem( "CHANGED-- *.?", $Folder);


while
* = original base
. = original period
? = original extension
Doesn't work, see Example #2 in post. The results need to work for all folder and file names.
MacOS Tahoe v26.5.1
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: Scripting: renameitem

Post by nas8e9 »

I'd try the simpler form:

Code: Select all

renameitem("CHANGED-- ", $folder);
The additional parameters (including the "?"-wildcard) only come into play when actually wanting to change the extension, whereas you just want to take the full original name (whether it could be said to have an extension or not) and prepend it.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Scripting: renameitem

Post by Stefan »

Zardoz2293 wrote:Doesn't work, see Example #2 in post.
Only for an short time (till an refresh?)
And; trailing dots are not allowed by the file system anyway and removed automatically.
The results need to work for all folder and file names.
Yes, it will work.
flags 0: [Default] Smart (keep extension unless extension is passed)

nas8e9 wrote:I'd try the simpler form:

Code: Select all

renameitem("CHANGED-- ", $folder);
That would not keep the original name parts.

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: Scripting: renameitem

Post by nas8e9 »

Stefan wrote:
nas8e9 wrote:I'd try the simpler form:

Code: Select all

renameitem("CHANGED-- ", $folder);
That would not keep the original name parts.
You're right, sorry :oops:. I meant:

Code: Select all

renameitem("CHANGED-- *", $folder);
(Missed the "*"wildcard.)

Zardoz2293
Posts: 616
Joined: 09 Nov 2011 20:20
Location: USA

Re: Scripting: renameitem

Post by Zardoz2293 »

Gentlemen, have you tested both of these folder cases and the result value returned from renameitem:

Before:

Code: Select all

C:\Test\v3.64 (2010-12-10)            <DIR>
C:\Test\v3                            <DIR>
After:

Code: Select all

C:\Test\CHANGED-- v3.64 (2010-12-10)   <DIR>
C:\Test\CHANGED-- v3                   <DIR>
Depending on the target format string used, you can get a return value that is invalid. Specifically, where "v3" folder is renamed, but the return value is "v3." Try the above tests and add this script code at the end with the result value returned from renameitem

Code: Select all

$result = renameitem( "CHANGED-- *", $Folder ); // Any combination to get the "After" results
goto $result
MacOS Tahoe v26.5.1
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: Scripting: renameitem

Post by nas8e9 »

@Zardoz2293: After testing, this form of the command works for me:

Code: Select all

$result = renameitem("CHANGED-- *", $folder, 3);
Going by your first post in this thread, you simply needed to add the numeric flags into a single number, rather than specifying them individually the way you did.

Zardoz2293
Posts: 616
Joined: 09 Nov 2011 20:20
Location: USA

Re: Scripting: renameitem

Post by Zardoz2293 »

nas8e9 wrote:@Zardoz2293: After testing, this form of the command works for me:

Code: Select all

$result = renameitem("CHANGED-- *", $folder, 3);
Going by your first post in this thread, you simply needed to add the numeric flags into a single number, rather than specifying them individually the way you did.
The way I did the notation, { 0 | 1 | 2 } was to represent either of the values, not as how the command is actually used in the scripting. I'd assume it would default to 0 based on not meeting any valid criteria, if that was literally used. Just out of curiosity have you used the example you've provided, your script, with the two folder names I provided to get the desired results (using the "before" and "after")? Just curious. No reason, just curious.
MacOS Tahoe v26.5.1
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: Scripting: renameitem

Post by nas8e9 »

Zardoz2293 wrote:Just out of curiosity have you used the example you've provided, your script, with the two folder names I provided to get the desired results (using the "before" and "after")? Just curious. No reason, just curious.
May I thank and congratulate you on your patience :oops:? I've been meddling in this thread while trying to do other stuff simultaneously, which doesn't bode well for the other stuff either.

Best as I can tell, the sting is that I'm going by the UI route to the Batch Rename-mode of the rename-command, while the renameitem-function (with apparently only one mode) seems to differ from that. My best guess (ha!) at the moment is that this part of the renameitem-function is causing trouble:
flags

0: [Default] Smart (keep extension unless extension is passed)
1: Rename base (keep extension)
2: Rename extension (keep base)
[1 + 2 = 3: Rename all (base and extension)]
4: Show dialog (Suffix / Overwrite) on name collision.
Notes:
1 and 2 are only applicable if sourceitem is a file, not a folder.
In short, this should be doable with the rename-command, but not with the renameitem-function. As you depend on the return value, that's not good.

Zardoz2293
Posts: 616
Joined: 09 Nov 2011 20:20
Location: USA

Re: Scripting: renameitem

Post by Zardoz2293 »

nas8e9 wrote:In short, this should be doable with the rename-command, but not with the renameitem-function. As you depend on the return value, that's not good.
I've tried all the combinations before I posted and felt like a total idiot not understanding why I was getting funky results from time to time. The return value is incorrect for folders that have no extension. It renames correctly on disc but the return value has a period at the end. Then if you use this return value in other functions you have an error. Having to parse the return value for the period isn't an option in my book. I totally avoid using the "*" and "?" performed the calculation myself, which was extremely easy, I just wanted to know what the problem was, is, or what monkey brain thing I was doing wrong.

I love that Batch Rename (BR) in the UI. I'm assuming you are referencing some command ID for the BR? I need to research the command ID thingy as I don't understand the paradigm model of it. It makes me think: "Script? a Macro? What's the difference?" (if you don't get it, don't be concerned, neither do it.)

BTW, in case you haven't tried those two folder samples with that renameitem call as specified, it works for one but not the other.
MacOS Tahoe v26.5.1
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%

admin
Site Admin
Posts: 66252
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Scripting: renameitem

Post by admin »

This is a bug. Fix comes.

admin
Site Admin
Posts: 66252
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Scripting: renameitem

Post by admin »

Fix okay?

Zardoz2293
Posts: 616
Joined: 09 Nov 2011 20:20
Location: USA

Re: Scripting: renameitem

Post by Zardoz2293 »

admin wrote:Fix okay?
Working like a champ! Thanks!!!
MacOS Tahoe v26.5.1
VM (Client): Windows 11 Pro (AArch64), 25H2.26200.8655 (10.0)
Display: Main=MacBook 4112 x 2658 @200%; External 3840 x 2160 @125%

Post Reply