Core\FileTransfer\Entry::relativePath
$entry->relativePath(): stringReturns the path of a file or folder below the folder that list or walk started in.
A walk in reports gives the relative path 2026-01.csv for the file reports/2026-01.csv. A file two levels down has the relative path archive/2025-12.csv. For list, the relative path is the same as name(), because list reads only one folder. For metadata, it is the same as path(). The parts of the path are separated by / on every system.
The server sends the names, so the relative path 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. To use it as a file path on your own computer, check it with Core\IO::within first. That method checks that the path stays inside a folder you name.
Use path() for the whole path below the root of the block.
The examples below walk a sub-folder, compare list, walk and metadata, and print a folder tree.
Return value
Returns string. The path, with / between folders. For metadata, it is the same as path().
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"]Walk a sub folder
<?nvs// Shows the relative path of each entry when `walk` starts in a sub-folder.
var $partner = Core\FileTransfer::open('partner');
// The walk starts in "reports", so no relative path includes `reports/`.// This prints "2026-01.csv", "2026-02.csv", "archive" and "archive/2025-12.csv".foreach ($partner->walk('reports') as Core\FileTransfer\Entry $entry) { echo $entry->relativePath(), "\n";}2026-01.csv2026-02.csvarchivearchive/2025-12.csvList walk and metadata
<?nvs// Shows the relative path that `list`, `walk` and `metadata` give for the same folder.
var $partner = Core\FileTransfer::open('partner');
// `list` reads one folder, so each relative path is only a name.// This prints "list: 2025-12.csv".foreach ($partner->list('reports/archive') as Core\FileTransfer\Entry $entry) { echo 'list: ', $entry->relativePath(), "\n";}
// This walk starts at the root, so the relative path includes the folders `reports/archive/`.// This prints "walk: reports/archive/2025-12.csv".foreach ($partner->walk() as Core\FileTransfer\Entry $entry) { if ($entry->name() == '2025-12.csv') { echo 'walk: ', $entry->relativePath(), "\n"; }}
// For `metadata`, the relative path is the same as `path()`.// This prints "metadata: reports/archive/2025-12.csv".echo 'metadata: ', $partner->metadata('reports/archive/2025-12.csv')->relativePath(), "\n";list: 2025-12.csvwalk: reports/archive/2025-12.csvmetadata: reports/archive/2025-12.csvPrint a folder tree
<?nvs// Shows how a program prints the files and folders on a server as a tree.
var $partner = Core\FileTransfer::open('partner');
// This prints "orders.csv" and "reports/" first. The last line is " 2025-12.csv".foreach ($partner->walk() as Core\FileTransfer\Entry $entry) { // Each `/` in the relative path is one level down. Each level adds two spaces. uint $depth = Core\Str::countOf($entry->relativePath(), '/'); echo Core\Str::repeat(' ', $depth), $entry->name(), $entry->isDirectory() ? '/' : '', "\n";}orders.csvreports/ 2026-01.csv 2026-02.csv archive/ 2025-12.csv