Re: Minor scripting related wishes (a generic thread)
Posted: 18 Mar 2015 16:56
irresistible 
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
Code: Select all
$permPrefix = '$P_LAYOUT_';
// Create perm vars for the layout options
foreach ($opt, setlayout(), ',') {
$var = $permPrefix . GetToken($opt, 1, '=');
perm *$var = GetToken($opt, 2, '=');
}
// do stuff with them.
// Cleanup.
releaseglobals 2, $permPrefix . '*';Code: Select all
+ SC releaseglobals enhanced: The new parameter 'pattern' makes it
possible to release only those variables with specific names:
Syntax: releaseglobals [flags=3], [pattern=*]
pattern: Name pattern of variables to release.
Supports wildcards, but does not surround non-wildcard
containing patterns automatically.
(ie 'FOO' is not treated as '*FOO*')
Defaults to '*' to match all.
Examples:
// These are all equivalent &
// release all global & permanent variables
releaseglobals;
releaseglobals , '*';
releaseglobals 3, '*';
// Release all global & permanent variables containing 'FOO':
releaseglobals , '*FOO*';
// Release permanent variables starting with '$P_FOO_':
releaseglobals 2, '$P_FOO_*';
// Release all global variables ending with '_OLD':
releaseglobals 1, '*_OLD';
You can do yourself:zer0 wrote:Currently, when running multiple commands as part of a script, status bar reflects only the time taken to execute the latest command. I would like to see some kind of "encapsulation" switch that would show the total time taken to perform the task end to end.
Case in point: I have a CTB that runs a report dump of my external drives. I am not particularly interested in how long each dump takes -- since the status bar info is constantly changing -- but the total time taken is a figure that I would like to see at the end.
Code: Select all
$time0 = <date yyyy-mm-dd hh:mm:ss.fff>;
... commands you want to measure
$time1 = <date yyyy-mm-dd hh:mm:ss.fff>;
$timed1 = DateDifF($time0, $time1, 'ms'); // calculate time in msecCode: Select all
$time0 = now('msecs');
... commands you want to measure
$time1 = now('msecs');
$timed1 = $time1 - $time0;What's the actual code that is causing multiple updates to the status bar?zer0 wrote:Thanks chaps. I know that timing at the start and end is a workaround, but I was hoping for a more logical change, such prefixing a block of code with an identifier that specifies how its execution time should be displayed.
Several sequential folderreport() with dump switch. It shows traversal of the file system of each location and then finishes with how long it took. Therefore, the only data I really get is how long it took to do a report on the last place in the list.TheQwerty wrote:What's the actual code that is causing multiple updates to the status bar?zer0 wrote:Thanks chaps. I know that timing at the start and end is a workaround, but I was hoping for a more logical change, such prefixing a block of code with an identifier that specifies how its execution time should be displayed.
I don't think it's going to be easy for Don to just add a command to collate the status bar updates into a single update to show the total time, because it is code called by folderreport that is updating the status bar and not the code actually executing the script commands.zer0 wrote:Several sequential folderreport() with dump switch. It shows traversal of the file system of each location and then finishes with how long it took. Therefore, the only data I really get is how long it took to do a report on the last place in the list.
Well, each folderreport is for a different drive and writes a report into a text file that's named according to the location being reported on. If respective pairs of "folder" and "outputfile" can be maintained thenTheQwerty wrote:What if the folderreport accepted a list of folders instead of just a single one and then reported on the total time taken? Would that be agreeable or are your calls to folderreport different enough that this could not work?
If I got it right DateDiff() could show a difference of 1ms on my example?TheQwerty wrote:I'd recommend using:If only because DateDiff doesn't always act as one might expect.Code: Select all
$time0 = now('msecs'); ... commands you want to measure $time1 = now('msecs'); $timed1 = $time1 - $time0;
Beg your pardon, but: $c=Null; is wrong syntax, it must be $c='Null';SammaySarkar wrote:While doing this (http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=13822), I missed the absence of the null.
Can you introduce a null value that evaluates to true emptiness and not just an empty string?
Because ::$c = Null; getpathcomponent(<curpath>,$c,); is not the same as ::$c = '';/*or set $c;*/ getpathcomponent(<curpath>,$c,);
Code: Select all
$a = func(''); // func uses ''
$a = func(); // func uses 'dflt'
$a = func('dflt'); // func uses 'dflt'
$a = func('dings'); // func uses 'dings'
Function func( $p='dflt') {Echo $p;}