Futilities/v0.6/clade/Sys/IO/Store/Spider/@fx/OnPath

From WoozleCodes
Jump to navigation Jump to search

About

  • Purpose:
    • MAIN: filter out links, check whether file/folder, dispatch to appropriate event-handler
    • AUX: optionally show items as they are found, where requested
  • Rule We have a valid path to a file or folder that we do want to consider.
    • For now, we assume no '.', '..', or links. We might enable link-inclusion as an option, later.

History

  • 2022-08-31 oops, forgot to include the link-check. Fixed.
  • 2022-10-16 updating to handle more complete logging options

Code

as of 2026-05-05:

#
    protected function OnPath(FNodeIface $of) {
        $ofIdent = $of->Ident();
        if ($ofIdent->IsRegular()) {

            // calculations for output list
            $om = $this->GetMatcher();
            $oOpts = $om->OOptions;

            $oOptsList = $oOpts->ListingOptions();  // get Listing sub-options

            $doLFi = $oOptsList->DoFiles();
            $doLFo = $oOptsList->DoFolders();
            $useScreen = $oOptsList->UseScreen();
            $oLog = $this->Logger();

            if ($doLFi or $doLFo) {
                $fs = $ofIdent->Raw();
            }

            if ($ofIdent->IsFolder()) {
                if ($doLFo) {
                    $snFo = $this->FoCount();
                    $s = "[$snFo FO] $fs";
                    if ($useScreen) { echo $s."\n"; }
                    $oLog->WriteLn($s);
                }
                $this->OnFolder($of);
            } else {
                if ($doLFi) {
                    $snFi = $this->FiCount();
                    $s = "[$snFi FI] $fs\n";
                    if ($useScreen) { echo $s; }
                    $oLog->WriteLn($s);
                }
                $this->OnFile($of);
            }
        }
    }