Multi Commander > Script
2 functions I'd like to see
Ulfhednar:
Thanks for spotting that issue Mathias. :)
My logic was to route the PathGetFileExtPart command to the array.
I must practice the design of separate loops for my defined processes
I will attempt to tidy it up !!
This works for now
--- Code: ---@var $ext = PathGetFileExtPart($arr, 0);
--- End code ---
I need to recurse my selections.
I had been applying the idea to only one file at a time but your comment on different extensions has made me think about multiple types & defining multiple arrays - new ground for me but definitely useful to be expanding my envelope. ;)
Mathias (Author):
--- Quote from: Ulfhednar on February 16, 2015, 13:04:57 ---
--- Code: ---@var $ext = PathGetFileExtPart($arr, 0);
--- End code ---
--- End quote ---
No.. still wrong. you can NOT send $arr (if it is an Array) to PathGetFileExtPart
See : http://multicommander.com/docs/multiscript/functions/filesystem#pathgetfileextpart
It takes a <str> (string)
and Array is a list/Collection of 0->N number of strings (or nums)
You need to get the string out of the Array first, Just as you do in the loop for
$CurrentNameFullPath = $arr[ $n ];
Since you already get the string from the Array in the loop then just sen $CurrentNameFullPath to PathGetFileExtPart. like
PathGetFileExtPart( $CurrentNameFulllPath );
Ulfhednar:
I will try not to ruin your day ::) :)
I had tried
--- Code: ---@var $extPathGetFileExtPart( $CurrentNameFullPath );
--- End code ---
this fails - I assume because I haven't defined $CurrentNameFulllPath previously (in my script above)
I realize array can = group of strings, I need to select one element of the group.
Will continue trying :P
Mathias (Author):
?? no no no :)
What are you doing.....
--- Code: ---@var $extPathGetFileExtPart( $CurrentNameFullPath );
--- End code ---
I don't really understand how you are thinking, You can not used variables as if they are function.
functions and variables are two different things.. a variable is a "name" that holds a value of a set type.
$CurrentNameFullPath is defined at the beginning of your script so it exits.
just spell it the same.
So your script should be something like (not tested)
--- Code: ---@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $NewName= GetClipboardText();
@var $n = 0
@var $ext;
// name from clipboard
for( $n = 0; $n < $items; $n++ )
{
$CurrentNameFullPath = $arr[ $n ];
// PathGetFileExtPart moved INTO the LOOP and uses currentNameFullPath that we already got above
$ext = PathGetFileExtPart( $CurrentNameFullPath );
$OrgName = PathGetNamePart( $CurrentNameFullPath );
RenameFile( $CurrentNameFullPath, $NewName+$ext, );
}
--- End code ---
BUT if you select multiple files with same extension... you will get duplicated new names
Ulfhednar:
--- Quote ---I don't really understand how you are thinking,
--- End quote ---
Me neither :o ;D
I seem to have forgotten a lot since I tried using MCscript last!
My concept of vars vs funcs has blurred :-[
Returning to MC script after a long break (+ flu last week) might not have been such a good idea.
Unfortunately I find your script interesting & know just enough to cause you trouble!
I see that it is necessary to define some parameters in the @var list, I do not yet know where to divide what is possible & what is correct (as you noticed).
I'd decided to use GetSourceFocusPath before I read your reply, as this gave me a string.
Moving $ext down into the loop is something that I had not thought about, yet is obvious now you say it.
I ended up with -
--- Code: ---@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath = GetSourceFocusPath()
@var $OrgName;
@var $NewName= GetClipboardText();
@var $ext;
@var $n = 0;
// name from clipboard
for( $n = 0; $n < $items; $n++ )
{
$CurrentNameFullPath = $arr[ $n ];
$OrgName = PathGetNamePart( $CurrentNameFullPath );
$ext = PathGetFileExtPart( $CurrentNameFullPath );
RenameFile( $CurrentNameFullPath, $NewName+$ext, );
}
--- End code ---
Works for multiple names on files with different exts. hopefully this is closer to what you know to be correct.
Thanks for the help!
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version