Page 1 of 1

Action on each selected items

Posted: 24 Nov 2014 20:35
by lian00
Hello,
sorry for noob question but I've read a lot of the help and on the forum and don't know how to do.

I've written a little script with resize an image using Irfanview command line. I select the file, click on the button and it works.

Code: Select all

 $largeur = input("Largeur", "Taille", , [style=s], [cancel], [width=600], [height=400]);
 $script= '"C:\Program Files\IrfanView\i_view32.exe" '." <curitem>"." /resize=("."$largeur".","."$largeur".") /aspectratio /resample /convert=E:\images\Output\"."<curname>";
 run $script;
Now I want to make the same with some selected files. As I understand I must create a list and work on each file from the list but I cannot manage it.

I took a look at get("SelectedItemsPathNames", ,); and paperfolder("Favs", "<get selecteditemspathnames |>", "|", "as");

Thanks for your help.

Re: Action on each selected items

Posted: 24 Nov 2014 20:58
by highend
You "only" need a foreach loop

Code: Select all

foreach($file, "<get SelectedItemsPathNames |>") {
    // the code that will be executed
}

Code: Select all

$largeur = input("Largeur", "Taille", , [style=s], [cancel], [width=600], [height=400]);
The params with a surrounding [] are optional. It makes no sense to write them in that style :)

Maybe something like this:

Code: Select all

    $largeur = input("Largeur", "Taille");
    foreach($file, "<get SelectedItemsPathNames |>") {
        run """C:\Program Files\IrfanView\i_view32.exe"" ""$file"" /resize=($largeur, $largeur) /aspectratio /resample /convert=""E:\images\Output\""", , 1;
    }
You have to check the quoting in the run command...

Re: Action on each selected items

Posted: 25 Nov 2014 15:58
by lian00
Thank you. I managed with your help.

For Irfanview users: as I did not find how to grab the name of the file in the loop, I used

Code: Select all

"C:\Program Files\IrfanView\i_view32.exe" "$file" /resize=($largeur, $largeur) /aspectratio /resample /convert=""E:\images\Output\$N.jpg
$N is used by Irfanview to get the name of the file converted.

Re: Action on each selected items

Posted: 25 Nov 2014 16:02
by highend
as I did not find how to grab the name of the file in the loop, I used

Code: Select all

/convert=""E:\images\Output\<curname>"""

Re: Action on each selected items

Posted: 25 Nov 2014 16:23
by lian00
highend wrote:
as I did not find how to grab the name of the file in the loop, I used

Code: Select all

/convert=""E:\images\Output\<curname>"""
It does not work with curname - I've tested it: it gives the name of the first file in the selection and do not change with the loop.

Re: Action on each selected items

Posted: 25 Nov 2014 16:33
by bdeshi
Try These in place of /convert=""E:\images\Output\<curname>""":

Code: Select all

/convert=""E:\images\Output\".getpathcomponent($file,file).'"'

Code: Select all

/convert=""E:\images\Output\".regexreplace($file, ".+\\").'"'

Re: Action on each selected items

Posted: 25 Nov 2014 16:50
by lian00
Thanks for the suggestion but for the moment I will keep $N as it works perfectly but I will remember your code for future scripts.