Core\FileTransfer\Entry::name
$entry->name(): stringReturns the name of a file or folder on the server, without the folders above it.
The name is the last part of path(). For reports/2026-01.csv, the name is 2026-01.csv. For a folder, it is the folder's own name, such as reports. The name never contains a /.
The server sends the names, so the name is a tainted string. Tainted means that the value comes from outside your program and must be checked before some uses. You can print it, compare it and check its extension. A program that passes it to Core\IO::write as a local file path does not compile. A program that stores it in a Core\Html\Markup variable to use it as HTML does not compile either. Escape it with Core\Html::escape first.
Use the name to check a file's extension, or to find a file with a known name. Use path() for the folder the file is in.
The examples below print the names in one folder, compare each name with its path, and find the reports of one year by their names.
Return value
Returns string. The name.
Changelog
| Version | Change |
|---|---|
0.0.6 | list 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.
# 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"]Names in a folder
<?nvs// Shows the name of each file and folder in one folder on the server.
var $partner = Core\FileTransfer::open('partner');
// A folder has a name too. This prints "2026-01.csv", "2026-02.csv" and "archive".foreach ($partner->list('reports') as Core\FileTransfer\Entry $entry) { echo $entry->name(), "\n";}2026-01.csv2026-02.csvarchiveThe last part of the path
<?nvs// Shows that `name()` is the last part of `path()`.
var $partner = Core\FileTransfer::open('partner');
// Each line shows the path, then the name.// The last line is "reports/archive/2025-12.csv -> 2025-12.csv".foreach ($partner->walk() as Core\FileTransfer\Entry $entry) { echo $entry->path(), ' -> ', $entry->name(), "\n";}orders.csv -> orders.csvreports -> reportsreports/2026-01.csv -> 2026-01.csvreports/2026-02.csv -> 2026-02.csvreports/archive -> archivereports/archive/2025-12.csv -> 2025-12.csvFind the reports of one year
<?nvs// Shows how a program finds the CSV reports of one year by their names.
var $partner = Core\FileTransfer::open('partner');uint $found = 0;
foreach ($partner->walk('reports') as Core\FileTransfer\Entry $entry) { // `Core\Path::extension` returns the part after the last dot, here "csv". bool $isReport = $entry->isFile() && Core\Path::extension($entry->name()) == 'csv'; if ($isReport && Core\Str::startsWith($entry->name(), '2026-')) { echo $entry->name(), "\n"; $found = $found + 1; }}
// "2025-12.csv" is from another year. This prints "2 reports from 2026".echo $found, ' reports from 2026', "\n";2026-01.csv2026-02.csv2 reports from 2026