Skip to content

Core\IO\Entry

One file or folder that Core\IO::walk found. It has the entry's path, its name and its kind. For the size or the time it was changed, call Core\IO::metadata($entry->path()).

Core\IO\Entry is one file or folder that Core\IO::walk gives in its foreach loop. You do not create one yourself.

path() is the folder you gave walk, joined to the entry. You can pass it to Core\IO::readText, Core\IO::open or Core\IO::metadata. relativePath() is the path from that folder, such as images/logo.svg. On Windows, its folder names are separated by \. name() is the last part of the path, such as logo.svg.

isFile(), isDirectory() and isLink() tell you what the entry is. A symbolic link, or a junction on Windows, is a link: isLink() is true and the other two are false. A device, socket or pipe is none of the three. To get the size or the time of the last change, call Core\IO::metadata($entry->path()).

You can keep an entry after the loop, and pass it to another task.

jpg
jpg
<?nvs
foreach (Core\IO::walk('photos') as Core\IO\Entry $entry) {
string $kind = $entry->isDirectory() ? 'folder' : 'file';
// This changes `\` to `/`, so the output is the same on every system.
string $path = Core\Str::replace($entry->relativePath(), Core\Path::SEPARATOR, '/');
echo $kind, ' ', $entry->name(), ' ', $path, "\n";
}
Output
folder 2024 2024
file city.jpg 2024/city.jpg
file beach.jpg beach.jpg

Members

6 members.

MemberSignature
pathpath(): string
relativePathrelativePath(): string
namename(): string
isFileisFile(): bool
isDirectoryisDirectory(): bool
isLinkisLink(): bool