Skip to content

Core\FileTransfer\Entry::isDirectory

$entry->isDirectory(): bool

Checks whether an entry that list, walk or metadata gave is a folder.

$entry->isDirectory() returns true for a folder. It returns false for a file and for a symbolic link, even when the link points to a folder. A symbolic link is a name that points to another file or folder. walk lists what is in every folder. It gives a link as one entry, and it does not list what is in the link's target.

A folder has no size, so size() returns null for it. Check isDirectory() to skip folders when you download files, or to collect the folders that exist on the server.

The examples below print the path of each folder, and print the size of each file in a folder and the word "folder" for each folder in it. The last one checks that the folders for an upload exist.

Return value

Returns bool. true for a folder. A link is not a folder.

Changelog

VersionChange
0.0.6list and walk return one Core\FileTransfer\Entry for each file or folder, and it has the same methods as Core\IO\Entry. Its size, modifiedAt and permissions methods return null when the server does not send the value. Every string it returns is tainted: the server chose it, so the methods of the connection do not accept it until your program checks it.

Examples

The examples below run with this configuration file.

nvs.toml
# The `partner` block reads the folder `partner` beside this file. It needs no server.
[file_transfer.partner]
directory = "partner"
# The program may open the `partner` block and read its folder.
[capabilities.file_transfer]
connect = ["partner"]
[capabilities.fs]
read = ["partner"]

List the folders

<?nvs
// Shows the path of each folder on the server.
var $partner = Core\FileTransfer::open('partner');
// This prints "reports" and "reports/archive".
foreach ($partner->walk() as Core\FileTransfer\Entry $entry) {
if ($entry->isDirectory()) {
echo $entry->path(), "\n";
}
}
Output
reports
reports/archive

Files with their sizes

<?nvs
// Shows how to print the size of each file in a folder, and the word "folder" for each folder.
var $partner = Core\FileTransfer::open('partner');
// A folder has no size, so this prints "archive: folder" for it.
foreach ($partner->list('reports') as Core\FileTransfer\Entry $entry) {
if ($entry->isDirectory()) {
echo $entry->name(), ': folder', "\n";
} else {
echo $entry->name(), ': ', $entry->size() ?? 0, ' bytes', "\n";
}
}
Output
2026-01.csv: 25 bytes
2026-02.csv: 25 bytes
archive: folder

Check the folders before an upload

<?nvs
// Shows how a program checks that the folders it uploads to exist on the server.
var $partner = Core\FileTransfer::open('partner');
// The program reads the paths of all folders once.
array<tainted string> $folders = [];
foreach ($partner->walk() as Core\FileTransfer\Entry $entry) {
if ($entry->isDirectory()) {
$folders[] = $entry->path();
}
}
// "outbox" is not on the server. This prints "outbox: missing".
array<string> $needs = ['reports', 'reports/archive', 'outbox'];
foreach ($needs as string $needed) {
bool $found = false;
foreach ($folders as tainted string $folder) {
if ($folder == $needed) {
$found = true;
}
}
echo $needed, ': ', $found ? 'ready' : 'missing', "\n";
}
Output
reports: ready
reports/archive: ready
outbox: missing