Page 1 of 1
^ Scripting: renameitem (Bug, Resolved)
Posted: 31 Jan 2012 14:03
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?
Re: Scripting: renameitem
Posted: 31 Jan 2012 14:33
by Stefan
Try
renameitem( "CHANGED-- *.?", $Folder);
while
* = original base
. = original period
? = original extension
Re: Scripting: renameitem
Posted: 31 Jan 2012 15:12
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.
Re: Scripting: renameitem
Posted: 31 Jan 2012 15:25
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.
Re: Scripting: renameitem
Posted: 31 Jan 2012 15:45
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.
Re: Scripting: renameitem
Posted: 31 Jan 2012 15:50
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

. I meant:
Code: Select all
renameitem("CHANGED-- *", $folder);
(Missed the "*"wildcard.)
Re: Scripting: renameitem
Posted: 31 Jan 2012 16:33
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
Re: Scripting: renameitem
Posted: 31 Jan 2012 17:42
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.
Re: Scripting: renameitem
Posted: 31 Jan 2012 18:36
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.
Re: Scripting: renameitem
Posted: 31 Jan 2012 19:55
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

? 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.
Re: Scripting: renameitem
Posted: 31 Jan 2012 20:28
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.
Re: Scripting: renameitem
Posted: 31 Jan 2012 20:32
by admin
This is a bug. Fix comes.
Re: Scripting: renameitem
Posted: 02 Feb 2012 10:22
by admin
Fix okay?
Re: Scripting: renameitem
Posted: 08 Feb 2012 14:07
by Zardoz2293
admin wrote:Fix okay?
Working like a champ! Thanks!!!