klownboy wrote:So for this to work properly, you were relying on listfolder returning a "0" not a "" for situation where the folder exists but has no files
Yes... it was rather foolish of me to believe that if I ask for the count I'd always get the count and not an empty string.
Though since XY treats '' and 0 as false we can really change our test:
Code: Select all
"_check"
Global $thumbsfolder;
$exists = exists($thumbsfolder);
$f_check = ($exists == 0);
// If a folder, check if it is empty...
if ($exists == 2) {
$f_check = ! listfolder($thumbsfolder);
}
$thumbsfolder = "E: $exists - F: $f_check - $thumbsfolder";
"Test"
Global $thumbsfolder;
$result = '';
foreach($thumbsfolder, <<<PATHS
C:\
C:\test\
C:\test\empty
C:\test\fake
C:\test\file.txt
C:\test\fakefile.txt
PATHS
, "<crlf>") {
Sub '_check';
$result = $result . $thumbsfolder . "<crlf>";
}
Text $result;
With '! listfolder(...)' we now don't care if the count flag is used or not because XY will evaluate it as a boolean when not-ing it. This works because XY treats '' and 0 as false and non-empty strings as true in conditionals.
Going back to your other example we can do some re-formatting and probably make it:
Code: Select all
foreach($dat2file, $dat2, "<crlf>") {
$filehash = getpathcomponent($dat2file, "base"); //gets the base file name which is the "hash"
$dat2info = readfile("$dat2file", "b", 75, , 17); //reads each thumbnail ".dat2" file for the folder and thumbnail size
$thumbDBsize = formatbytes(filesize(replace("$dat2file", "dat2", "dbits")), MB); //obtain size of cache, "dbit" file size
$thumbsfolder = gettoken($dat2info, 1, "*", "t"); //extract the folder
$thumbssize = gettoken($dat2info, "2", "*", "t"); //extract the thumbnail size
$filedate = property("#3", "$dat2file"); //obtains the file date
// Determine if the path is non-existent / present.
$exists = exists($thumbsfolder);
$no_longer_exist = ($exists == 0);
// Also treat empty folders as non-existent.
if ($exists == 2) {
$no_longer_exist = ! listfolder($thumbsfolder);
}
//$thumbsfolder = "E: $exists - F: $no_longer_exist - $thumbsfolder";
// If item no longer exists - check it!
$f_check = $no_longer_exist ? '+' : '';
$thumbsmod = $thumbsmod . $f_check . $thumbsfolder . " " . $thumbssize . " " . $filedate . " " . $filehash . " " . $thumbDBsize . "<crlf>";
$thumbssync = $thumbssync . $f_check . $thumbsfolder . "|" . $thumbssize . "|" . $filehash . "<crlf>";}
}
Hopefully, I didn't make any mistakes or incorrect assumptions this time, but if so please forgive me for it is early and I haven't gotten my first dose of caffeine yet.
