Author Topic: 2 functions I'd like to see  (Read 27115 times)

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
2 functions I'd like to see
« on: February 14, 2015, 13:30:58 »
Wondering if it is possible to add script commands for
set output file-size for the packer function - for disk spanning etc. (The existing GUI packer dialog could also benefit from an output file-size setting option)
Get string from the clipboard - I thought of a button for renaming a file with clipboard text & moving it to a target folder

Obviously if it is a lot of work then don't worry too much about it ;)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4424
    • View Profile
    • Multi Commander
Re: 2 functions I'd like to see
« Reply #1 on: February 14, 2015, 14:22:46 »
Not sure what a "set output filesize" option for the packer function are useful for.. because none of the packers support Disk Spanning. (Yet. and kind of low prio)

Script function for "Get string from clipboard" already exists
http://multicommander.com/docs/multiscript/functions/misc#getclipboardtext


Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: 2 functions I'd like to see
« Reply #2 on: February 14, 2015, 22:23:16 »
get clipboard string - Hmm I am going blind - I looked for it & didn't find it....Sorry :-[

I would normally use 7zip for spanning - I had disk images I wanted to cut up to span DVDRs - then I thought of making a packer button to compare the functionality & didn't get too far. :)
It isn't  a necessity with things like 7zip around, but it felt strange not to see an output size field as I have got used to seeing so many fine details in your work. ;)

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: 2 functions I'd like to see
« Reply #3 on: February 15, 2015, 00:02:23 »
I came up with this, amazingly it works but I'm wondering if it is optimal.   

Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $NewName= GetClipboardText();
@var $ext = PathGetFileExtPart( $arr );
@var $n = 0

// name from clipboard

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
   
  RenameFile( $CurrentNameFullPath, $NewName+$ext, );
  }

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4424
    • View Profile
    • Multi Commander
Re: 2 functions I'd like to see
« Reply #4 on: February 15, 2015, 11:26:38 »
@var $ext = PathGetFileExtPart( $arr );
This is wrong. PathGetFileExtPart(..) takes a string. you send it an entire list of strings. By accident it "MIGHT" use the first string in the list.
But if you have files selected with different extension you will always set the same file extension.
You should do this inside the loop so the file get the same file extension that the file already have.


Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: 2 functions I'd like to see
« Reply #5 on: February 16, 2015, 13:04:57 »
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: [Select]
@var $ext = PathGetFileExtPart($arr, 0);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.  ;)
« Last Edit: February 16, 2015, 13:35:49 by Ulfhednar »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4424
    • View Profile
    • Multi Commander
Re: 2 functions I'd like to see
« Reply #6 on: February 16, 2015, 13:46:00 »
Code: [Select]
@var $ext = PathGetFileExtPart($arr, 0);

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

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: 2 functions I'd like to see
« Reply #7 on: February 16, 2015, 15:15:51 »
I will try not to ruin your day  ::) :)
I had tried
Code: [Select]
@var $extPathGetFileExtPart( $CurrentNameFullPath );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

« Last Edit: February 16, 2015, 17:22:48 by Ulfhednar »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4424
    • View Profile
    • Multi Commander
Re: 2 functions I'd like to see
« Reply #8 on: February 16, 2015, 16:51:17 »
?? no no no :)

What are you doing.....
Code: [Select]
@var $extPathGetFileExtPart( $CurrentNameFullPath );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: [Select]
@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, );
 }

BUT if you select multiple files with same extension... you will get duplicated new names
« Last Edit: February 16, 2015, 17:00:10 by Mathias (Author) »

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: 2 functions I'd like to see
« Reply #9 on: February 16, 2015, 17:52:02 »
Quote
I don't really understand how you are thinking,
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: [Select]
@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, );
}

Works for multiple names on files with different exts.  hopefully this is closer to what you know to be correct.
Thanks for the help!

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4424
    • View Profile
    • Multi Commander
Re: 2 functions I'd like to see
« Reply #10 on: February 16, 2015, 22:25:36 »
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!
MultiScript is actually not that strange. MultiScript is actually very similar to most programming languages. like Java,C#, C/C++ , PHP, JavaScript
It uses the same syntax style.  (Kind off)
But If you don't know any if them then I can understand you can have a hardtime understanding it.

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).
The Script engine must know that the variable exists before it can use it, So every variables must first be defined before it can be used.
Variables are just like the X , Y thing you did in maths in school..
Like "10 = 5 + X " then you know that X is 5. So X is a variable that has the value 5.
Same thing here but variables must have a $ before the name. This is just a help for the script engine to know that it is a variable and not something else

Ulfhednar

  • Contributor
  • VIP Member
  • *****
  • Posts: 514
    • View Profile
Re: 2 functions I'd like to see
« Reply #11 on: February 17, 2015, 13:19:10 »
I have a small amount of basic & C++ experience - but years ago....& a lot has changed!
So I have to learn/recall again. 

What had thrown me was the fact some vars were defined with = function & some not
eg
@var $arr = GetSourceSelectedPaths();
or
@var $ext;

Until you put the $ext in the loop, it obviously returned a single extension value for multiple different file types.
I since realized that assigning values to vars is conditional on the context.  [Cannot say why I forgot that!! :o]
Returning multiple ext values was dependent on the loop cycling. 
But I can see where both options could be used
- make all exts the same
- keep all exts as is.

I started thinking about the names being the same on multiple files with the same .ext.  Obviously this is made irrelevant by the use of Multi-rename, but I started to think about how to add that to the script as an experiment. 
I started with the idea to only name 1 file & now there is a holocaust of bad code imminent!!  :P

There are quite a lot of interesting possibilities in MC Script & I enjoy playing around with it.  Sorry for the torture it creates.  :)

I will have to look at some programming tutorials, to reduce the time I spend creating comedy scripts for you. ;)