XYplorer hangs on script execution

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
zakhar
Posts: 179
Joined: 08 Sep 2010 21:13

XYplorer hangs on script execution

Post by zakhar »

Hello all!

XYplorer hangs on execution of the script of the following content:

(XYplorer must
- find *.jpg- and *.txt-files,
- calculate their number and length,
- write these data into a file.
Hangs occurs if the number of file is over 4500.
If the amount of files is under 4500 XYplorer does not hang and works properly.)

Code: Select all

 $dateandtimeofstart = <date yyyy.mm.dd hh.nn.ss>;

 $dateforfile = gettoken ("$dateandtimeofstart",1," ",,);
 $timeforfile = gettoken ("$dateandtimeofstart",-1," ",,);
 $dateandtimeforfilename = "$dateforfile-$timeforfile";

 $folder = "C:\folder\";

 $searchresultjpg = quicksearch ("*.jpg /f", "$folder",<crlf>);
 $filecountjpg = gettoken ("$searchresultjpg","count",<crlf>,,);

 $i1 = 1;
 while ($i1 < "$filecountjpg" + 1) {

 $line = gettoken ("$searchresultjpg",$i1,<crlf>);
 $filesize = filesize ($line);
 $sumsizejpg = "$sumsizejpg"+"$filesize";

 $i1++;
 }

 $searchresulttxt = quicksearch ("*.txt /f", "$folder",<crlf>);
 $filecounttxt = gettoken ("$searchresulttxt","count",<crlf>,,);

 $i2 = 1;
 while ($i2 < "$filecounttxt" + 1) {

 $line = gettoken ("$searchresulttxt",$i2,<crlf>);
 $filesize = filesize ($line);
 $sumsizetxt = "$sumsizetxt"+"$filesize";

 $i2++;
 }

 writefile("C:\folder-1\$dateandtimeforfilename-files.txt","$folder<crlf>*.jpg $filecountjpg $sumsizejpg<crlf>*.txt $filecounttxt $sumsizetxt<crlf><crlf>",a,t);

 $dateandtimeofend = <date yyyy.mm.dd hh.nn.ss>;

 writefile("C:\folder-1\$dateandtimeforfilename-files.txt",">-$dateandtimeofstart<crlf>->$dateandtimeofend<crlf><crlf>",a,t);

 msg Script executed!;

Is there any way to avoid these hangs?
Should the sum of the file lengths be calculated in this script in an another way?

In the Info Panel the files are found very quickly and the sum of the lengths of the founded files is calculated automatically, very quickly, without problems.
It should be possible to get the sum of file lengths without hangs.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: XYplorer hangs on script execution

Post by PeterH »

At least for test: try, in both loops
$filesize = filesize ($line) / 1024; // size in kb
If it hangs much later you have reached a limit here.

And you should set $sumsizejpg and $sumsizetxt to 0 before looping. Though it seems that an uninitialized variable is trated as 0 in an arithmetic operation. I'm always cautious here...

By the way:
$sumsizejpg = "$sumsizejpg"+"$filesize";
tells to treat the vars as strings before adding them (by converting them to numbers).
$sumsizejpg = $sumsizejpg + $filesize;
just adds the contents of the variables.

zakhar
Posts: 179
Joined: 08 Sep 2010 21:13

Re: XYplorer hangs on script execution

Post by zakhar »

Adding /1024, predeclaring $'s = 0 and removing of "" seem not to help. :cry:
If it hangs much later you have reached a limit here.
It is interesting to know what kind of limit do I reach here. (?)

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

Re: XYplorer hangs on script execution

Post by highend »

You could use a folderreport() to get the necessary information (although this takes much longer than a quicksearch() on large folders) and then grab the necessary stuff via regexmatch and sum it up (via eval()). That would let you get rid of the while loops to do that stuff...
One of my scripts helped you out? Please donate via Paypal

zakhar
Posts: 179
Joined: 08 Sep 2010 21:13

Re: XYplorer hangs on script execution

Post by zakhar »

highend wrote:grab the necessary stuff via regexmatch
I will not be able to define the regular expression for regexpmatches to extract the numbers from the file or variable created by folderreport
as the regular expression syntax needed for regexpmatches is not documented enough in the help file of XYplorer (or I did not find needed information.). :cry:
Please point me to the needed information.

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

Re: XYplorer hangs on script execution

Post by highend »

Code: Select all

$files = folderreport("files:{size raw}+|{name}", "r", "<curitem>", "r", , "<crlf>");
$txtFiles = formatlist($files, "f", "<crlf>", "*.txt", "f");
regexreplace(regexreplace($txtFiles, "^(.*?)\|(.*$)", "$1"), "\r?\n")
Be careful, eval() has problems with larger stack sizes as well so you'll need a while loop that uses eval in blocks (e.g. 100 at a time)

I guess it's better to offload this procedure to a less limited language (e.g. .ahk)...
One of my scripts helped you out? Please donate via Paypal

zakhar
Posts: 179
Joined: 08 Sep 2010 21:13

Re: XYplorer hangs on script execution

Post by zakhar »

Thank you, highend! I will try to implement your code.

Post Reply