Skip to content

Core\FileTransfer\Entry::isLink

$entry->isLink(): bool

Checks whether an entry is a symbolic link. You get entries from list and walk. metadata gives the entry of one path.

A symbolic link is a name that points to another file or folder. $entry->isLink() returns true for a link. Then isFile() and isDirectory() both return false, even when the link points to a folder. For a regular file or a folder, isLink() returns false.

walk never follows a link. The result has the link, but not the files in the folder it points to. So a link to a folder above it cannot make walk read the same files again and again. path() is the path of the link itself.

A link can point to a file outside the folder you work with. A program that copies files usually skips links, or checks them by hand.

The examples below check the entries of a folder without links, sort each entry into a file, a folder or a link, and count the links a backup skips.

Return value

Returns bool. true for a link.

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"]

A folder without links

<?nvs
// Shows that `isLink()` returns `false` for each regular file and folder on the server.
var $partner = Core\FileTransfer::open('partner');
// This folder has no links, so each line ends with "link: no".
foreach ($partner->walk() as Core\FileTransfer\Entry $entry) {
echo $entry->path(), ' link: ', $entry->isLink() ? 'yes' : 'no', "\n";
}
Output
orders.csv link: no
reports link: no
reports/2026-01.csv link: no
reports/2026-02.csv link: no
reports/archive link: no
reports/archive/2025-12.csv link: no

Sort entries by kind

<?nvs
// Shows how to sort each entry into a file, a folder or a link.
class Kind
{
// `of` returns "link", "folder" or "file". A link is neither a file nor a folder.
public static function of(Core\FileTransfer\Entry $entry): string
{
if ($entry->isLink()) {
return 'link';
}
return $entry->isDirectory() ? 'folder' : 'file';
}
}
var $partner = Core\FileTransfer::open('partner');
// This folder has no links. This prints "orders.csv: file" and "reports: folder".
foreach ($partner->list() as Core\FileTransfer\Entry $entry) {
echo $entry->name(), ': ', Kind::of($entry), "\n";
}
Output
orders.csv: file
reports: folder

A backup skips links

<?nvs
// Shows how a backup job lists the files to copy, and counts the links it skips.
var $partner = Core\FileTransfer::open('partner');
uint $copied = 0;
uint $skipped = 0;
foreach ($partner->walk() as Core\FileTransfer\Entry $entry) {
// A link can point outside the folder, so the backup does not copy it.
if ($entry->isLink()) {
$skipped = $skipped + 1;
} elseif ($entry->isFile()) {
echo 'copy ', $entry->path(), "\n";
$copied = $copied + 1;
}
}
// This folder has no links, so this prints "4 files to copy, 0 links skipped".
echo $copied, ' files to copy, ', $skipped, ' links skipped', "\n";
Output
copy orders.csv
copy reports/2026-01.csv
copy reports/2026-02.csv
copy reports/archive/2025-12.csv
4 files to copy, 0 links skipped