Re: Automatic retrieval of tags from the filename
Posted: 30 Jan 2025 20:21
this
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
replace() / regexreplace()...Code: Select all
$allScripts = report("{basename} - ({comment})|",$allScripts);
$allScripts = replace($allScripts," - ()");
Code: Select all
$allScripts = listfolder(<xyscripts>, "*.xys");
$count_xys = gettoken($allScripts, "count", ",");
if ($count_xys) {
$allScripts = report("{basename} - ({comment})|",$allScripts);
$allScripts = replace($allScripts," - ());
$selectedscript = inputselect("Select one script to execute",$allScripts,,32);
If ($selectedscript>"")
{
$selectedscript = regexreplace($selectedscript, "(.+) -.+", "$1");
load $selectedscript;
}
} else {
$mycom = "This is a autocreated script";
writefile("<xyscripts>\hello.xys", " msg ""Your scripts folder not contain any script (*.xys)!<br>Warning:$mycom!<br>Script location is <xyscripts>"",48,,""$mycom"";");
tag $mycom, "<xyscripts>\hello.xys", 2;
load "<xyscripts>\hello.xys" }
}
Code: Select all
[CustomButtons]
Version=1
Count=1
1=""script launcher|:ladybug|0|0" $allScripts = listfolder(<xyscripts>, "*.xys"); ¶ $count_xys = gettoken($allScripts, "count", ",");¶ ¶ if ($count_xys) {¶ $allScripts = replace(report("{basename} - ({comment})|",$allScripts)," - ()");¶ $selectedscript = inputselect("Select one script to execute",$allScripts,,32);¶ If ($selectedscript>"") ¶ {¶ $selectedscript = regexreplace($selectedscript, "(.+) -.+", "$1");¶ load $selectedscript; ¶ }¶ } else {¶ $mycom = "This is a autocreated script";¶ writefile("<xyscripts>\hello.xys", " msg ""Your scripts folder not contain any script (*.xys)!<br>Warning:$mycom!<br>Script location is <xyscripts>"",48,,""$mycom"";");¶ tag $mycom, "<xyscripts>\hello.xys", 2;¶ load "<xyscripts>\hello.xys" }¶ } "
$count_xys = gettoken($allScripts, "count", ",");?listfolder() returns (by default) "|"-separated items so that count will always be one as long as at least one script existsCode: Select all
if ($allScripts) {
...
$allScripts = replace($allScripts," - ());If ($selectedscript>"")Code: Select all
$allScripts = listfolder(<xyscripts>, "*.xys");
end (!<get SelectedItemsPathNames>), "No item(s) selected, aborted!";
if ($allScripts) {
$allScripts = replace(report("{basename} - ({comment})|",$allScripts)," - ()");
$selectedscript = inputselect("Select one script to execute",$allScripts,,32);
If ($selectedscript) {
$selectedscript = regexreplace($selectedscript, "(.+) -.+", "$1");
load $selectedscript;
}
} else {
$mycom = "This is a autocreated script";
writefile("<xyscripts>\hello.xys", " msg ""Your scripts folder not contain any script (*.xys)!<br>Warning:$mycom!<br>Script location is <xyscripts>"",48,,""$mycom"";");
tag $mycom, "<xyscripts>\hello.xys", 2;
load "<xyscripts>\hello.xys" }
}