eil, as Ken (klownboy) said, the $f_ico variable isn't remembered when you click the button the second time. you need some persistent medium to hold the variable.
if you aggree to settle for a slightly different operation, you can use this script.
workflow: select exe or ico files and click the ctb. They are recorded in a file, <xyicons>\seticonlist.txt . Everytime you select exe/ico and click ctb, new icons are recorded if found. You can also select more than one file at once. So you can record all needed icons in one go before applying them.
Then select a folder and click the button to choose and apply the recorded icon. Right click the button to view the list or view CFI dialog. (read the comments in the code, there's a line you can uncomment which will remove used icons from the list)
Type
::snippet; into the addressbar and paste the following code, a new ctb will be created:
Code: Select all
Snip: CTB 1
XYplorer 14.20.0204, 6/21/2014 7:36:32 PM
Action
NewUserButton
Name
IconSetter
Icon
ScriptL
//path to iconlist
$list = "<xyicons>\seticonlist.txt";
//create the list file
if (exists("$list")==0){new("$list", "file");}
//set ctb on if list is not empty, off otherwise
//list is empty if it doesnt have any periods (.)
if (gettokenindex('.', readfile("$list"),<crlf>)!=0){ctbstate(1);ctbicon(":tagsrmv");}
else {ctbstate(0);ctbicon(":tagsadd");}
foreach ($item, <get SelectedItemsPathNames |>, "|"){
$ext = getpathcomponent("$item",ext);
//if selected items include files with exe or ico ext then...
if ($ext=="exe") || ($ext=="ico"){
//if the files is not listed already then...
if (gettokenindex("$item", readfile("$list"), <crlf>)==0){
//add it to the icon list
writefile("$list", "$item<crlf>", a);
}
}
}
//if curitem is folder...
if (exists("<curitem>")==2){
//popup saved icon list and...
$icon = popupmenu(readfile("$list"),,,,,,<crlf>,,'');
//if a menu item is selected, set that as folder icon
if ($icon != ''){
seticons("+<curitem>\>$icon",a,0); //definitions for the same folder is not overwritten
}
//uncomment following line to remove used icon from list
//writefile("$list",replacelist(readfile("$list"), "$icon|<crlf><crlf>", "|",'|'), o);
//^double crlf replacement attempts to remove extra empty lines
}
//check list and set ctbstate again
if (gettokenindex('.', readfile("$list"),<crlf>)==0){ctbstate(0);ctbicon(":tagsadd");}
else{ctbstate(1);ctbicon(":tagsrmv");}
ScriptR
"View Iconlist"
open "<xyicons>\seticonlist.txt"; //edit to match LClick script path
"Custom File Icons"
#605;
FireClick
0
[/size]
edit: multiple selections allowed