# disk-usage-insights/1.10/src/Domain/Collect/ScanDirForFilesJob.php

Disk Usage Insights, version 1.10. 60 lines.

- Page: https://pluginprobe.com/plugins/disk-usage-insights/1.10/code/src/Domain/Collect/ScanDirForFilesJob.php
- Raw: https://pluginprobe.com/plugins/disk-usage-insights/1.10/raw/src/Domain/Collect/ScanDirForFilesJob.php
- Modified: 2025-12-15T10:55:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/disk-usage-insights/1.10/code/src/Domain/Collect/ScanDirForFilesJob.php#L10-L20`.

```php
<?php

namespace Mgleis\DiskUsageInsights\Domain\Collect;

use Mgleis\DiskUsageInsights\Domain\FileEntry;
use Mgleis\DiskUsageInsights\Domain\Jobs\BaseJob;

class ScanDirForFilesJob extends BaseJob {

    private int $skip;
    private int $count;
    private int $totalCount;

    public function __construct(int $skip, int $count, int $totalCount) {
        $this->skip = $skip;
        $this->count = $count;
        $this->totalCount = $totalCount;
    }

    public function work() {

        $dirEntries = $this->fileEntryRepository->get($this->skip, $this->count, FileEntry::TYPE_DIR);
        $root = $this->snapshotRepository->load()->root;

        foreach ($dirEntries as $dirEntry) {

            $realDir = $this->fileEntryRepository->calcFullPath($dirEntry, $root);
            //$this->log("Scanning " . $realDir . " for files...");

            $files = scandir($realDir . '/');

            foreach ($files as $file) {
                if (!is_file($realDir . '/' . $file)) {
                    continue;
                }

                // persist file info
                $fileEntry = new FileEntry();
                $fileEntry->parent_id = $dirEntry->id;
                $fileEntry->name = $file;
                $fileEntry->type = FileEntry::TYPE_FILE;
                $fileEntry->size = 0;
                $this->fileEntryRepository->createOrUpdate($fileEntry);
            }
        }
    }

    public function toArray() {
        return ['type' => self::class, 'args' => [$this->skip, $this->count, $this->totalCount]];
    }

    public function toDescription(): string {
        $percent = $this->totalCount > 0
            ? round(100 * $this->skip / $this->totalCount)
            : '0';
        return sprintf('Scanning dirs for files... %s%%', $percent);
    }

}

```
