Action on each selected items

Discuss and share scripts and script files...
Post Reply
lian00
Posts: 429
Joined: 09 Jul 2014 17:12

Action on each selected items

Post 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.
Windows 10 64 bits

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Action on each selected items

Post 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...
One of my scripts helped you out? Please donate via Paypal

lian00
Posts: 429
Joined: 09 Jul 2014 17:12

Re: Action on each selected items

Post 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.
Windows 10 64 bits

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Action on each selected items

Post 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>"""
One of my scripts helped you out? Please donate via Paypal

lian00
Posts: 429
Joined: 09 Jul 2014 17:12

Re: Action on each selected items

Post 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.
Last edited by lian00 on 25 Nov 2014 16:49, edited 2 times in total.
Windows 10 64 bits

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Action on each selected items

Post 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, ".+\\").'"'
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

lian00
Posts: 429
Joined: 09 Jul 2014 17:12

Re: Action on each selected items

Post 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.
Windows 10 64 bits

Post Reply