Page 2 of 2
Re: Adding up the Length column
Posted: 19 Jul 2014 17:39
by TheQwerty
klownboy wrote:I'm not sure why there's a second "0" after the comment in that line of TheQwerty's original code ??
Code: Select all
// Retrieve the lengths as a mathematical equation.
// You may need to adjust the '{prop:*Length}' for your system.
Global $G_DURATION = Report('+{prop:*Length}', 0 /*use 1 for selection instead*/, 0);
The first zero tells Report to operate on all listed items, and as you and the comment say, changing it to 1 will work on the current selection instead.
The second zero is added as a "header" to the generated report so that we have a more valid equation. Without that zero the report would return:
with it a zero is added to the beginning making it:
Considering we modify the list later to remove empty tokens it is redundant and could be omitted.
Re: Adding up the Length column
Posted: 19 Jul 2014 18:10
by klownboy
Thanks TheQwerty for the explanation. I had read that the next parameter was the header but I didn't know you were purposely using the second "0" for that. I guess I was all "wet"...swimming in fact.

Re: Adding up the Length column
Posted: 17 Mar 2017 14:44
by yusef88
TheQwerty wrote:Nothing built-in but you can use Report + Eval to calculate the length.
Code: Select all
"Calculate Length"
// Retrieve the lengths as a mathematical equation.
// You may need to adjust the '{prop:*Length}' for your system.
Global $G_DURATION = Report('+{prop:*Length}', 0 /*use 1 for selection instead*/, 0);
// Remove items which didn't have a length.
$G_DURATION = FormatList($G_DURATION, 'tue', '+');
// Expand 'hh:mm:ss' to 'hh*60*60+mm*60+ss' so we calculate total seconds.
$G_DURATION = RegexReplace($G_DURATION, '(\d\d):(\d\d):(\d\d)', '$1*60*60+$2*60+$3');
// Do the math.
$G_DURATION = eval($G_DURATION);
Sub '_formatDuration';
Echo $G_DURATION;
"Format Duration in Seconds : _formatDuration"
Global $G_DURATION;
$Secs = $G_DURATION;
// Just stealing Don's code since I don't feel like doing this right now:
// Src: http://www.xyplorer.com/xyfc/viewtopic.php?p=57847#p57847
// format duration given in seconds
$DAYS_PER_YEAR = 365.25;
$HOURS_PER_DAY = 24;
$MINS_PER_HOUR = 60;
$SECS_PER_MIN = 60;
$duration = "";
$Mins = $Secs \ $SECS_PER_MIN;
$Hours = $Mins \ $MINS_PER_HOUR;
$Days = $Hours \ $HOURS_PER_DAY;
$Years = $Days \ $DAYS_PER_YEAR;
If ($Years > 0) {
$duration = $Years . "y";
}
$Days = $Days % $DAYS_PER_YEAR;
If ($Days > 0) {
$duration = $duration . " " . $Days . "d";
}
$Hours = $Hours % $HOURS_PER_DAY;
If ($Hours > 0) {
$duration = $duration . " " . $Hours . "h";
}
$Mins = $Mins % $MINS_PER_HOUR;
If ($Mins > 0) {
$duration = $duration . " " . $Mins . "min";
}
$Secs = $Secs % $SECS_PER_MIN;
If ($Secs > 0) {
$duration = $duration . " " . $Secs . "sec";
}
$G_DURATION = $duration;
first thanks for whom write this script, does it has limitation because I get error when calculating 2,425 files (in small lists works fine)
Code: Select all
Error: 28 (0x0000001C) Desc: Out of stack space Dll: 0 Proc: script_Process: set
Re: Adding up the Length column
Posted: 17 Mar 2017 14:52
by admin
I don't know the script, but something must be wrong with it when it errors out so soon. (I have no time to look into it.)
Re: Adding up the Length column
Posted: 17 Mar 2017 15:03
by yusef88
admin wrote:If you see that message the script is buggy. It will surely run out of any stack space you will give it. You better fix it.
viewtopic.php?f=3&t=10148
yeah, hoping someone of experts here will fix it

Re: Adding up the Length column
Posted: 17 Mar 2017 15:24
by bdeshi
the eval() fails with a large string (42715 chars in my case). Running a script to find minimum limit...
Re: Adding up the Length column
Posted: 17 Mar 2017 15:39
by highend
Just do the calculation in chunks (e.g. in 500er file blocks). Or Sammy finds the hard limit (that is true for all systems).
Then you could use this as the chunk size...
Re: Adding up the Length column
Posted: 17 Mar 2017 16:00
by bdeshi
Code: Select all
$l = 3283;
$t = trim(strrepeat("+1", $l), "+");
echo "eval() strlen:" . strlen($t); //6565
eval($t);
$l = 3284;
$t = trim(strrepeat("+1", $l), "+");
echo "eval() strlen:" . strlen($t); //6567
eval($t); // stack error
confirmation needed.
edit: by the way, putting the eval in a subscript (ie in more stacks) seems to further reduce the maximum length.
Code: Select all
global $l;
$l = 3283-16; // apparently limit reduced by 16 per stack?
sub "_eval_stress";
$l = 3283-15;
sub "_eval_stress";
"_eval_stress"
global $l;
$t = trim(strrepeat("+1", $l), "+");
echo "eval() strlen:" . strlen($t); //6567
eval($t);
Re: Adding up the Length column
Posted: 17 Mar 2017 16:15
by yusef88
SammaySarkar wrote:confirmation needed.
no errors here XY just hangs for few seconds (win 8.1)
Re: Adding up the Length column
Posted: 17 Mar 2017 16:20
by bdeshi
yusef88 wrote:SammaySarkar wrote:confirmation needed.
no errors here XY just hangs for few seconds (win 8.1)
So maybe dependent on available memory...
Re: Adding up the Length column
Posted: 17 Mar 2017 16:32
by yusef88
according to task manger available memory is 1.2 GB
Re: Adding up the Length column
Posted: 26 Jan 2018 20:26
by JLoftus
Found this searching for exactly what the OP was looking for.
Thank you TheQwerty!
I tweaked it to display in my preferred format, instead of 1d 13h 6m 4s, I wanted just DD:HH:MM:SS (with leading zeros), so now it's 01:13:06:04
Attached for anyone else that might like that format.