Core\Path
Reads and builds file paths as text. It never touches the disk. Every method accepts / and \ as separators on every platform, and writes Path::SEPARATOR.
Core\Path is string algebra over path text: no member reads the disk, so nothing here needs a capability, follows a symlink or checks that a file exists — that is Core\IO. Both / and \ are accepted on every platform, and a member that answers a path renders it with Core\Path::SEPARATOR — \ on Windows, / elsewhere. join only appends: a segment's own leading separator or drive is dropped rather than allowed to replace the base. normalize resolves . and .. lexically; neither member makes an untrusted path safe, which is Core\IO::within. Absence is null: extension on a name without one, relativeTo where no relative path exists.
matches checks whether a path matches a pattern, such as *.jpg or src/**/*.nvs. The pattern syntax is the same on every system. A pattern without a / is compared with the file name at any depth. A pattern with a / is compared from the start of the path. * matches any text inside one folder name, and ** matches any number of folders. Core\IO::walk uses the same syntax in its skip option.
<?nvsclass Show{ // A rendered path carries the platform's separator; print it as `/` either way. public static function slash(string $p): string { return Core\Str::replace($p, Core\Path::SEPARATOR, '/'); }}string $p = '/var/www/html/index.php';echo Core\Path::fileName($p), ' ', Core\Path::fileName($p, { withoutExtension: true }), ' ', Core\Path::extension($p) ?? 'none', "\n";echo Show::slash(Core\Path::parent($p)), ' ', Show::slash(Core\Path::parent($p, { levels: 2 })), "\n";echo Show::slash(Core\Path::withExtension($p, 'html')), "\n";echo Show::slash(Core\Path::join('/var/www', 'html', '/index.php')), "\n";echo Show::slash(Core\Path::normalize('/var/www/../log/./app.log')), "\n";echo Show::slash(Core\Path::relativeTo('/var/log/app.log', '/var/www') ?? 'none'), "\n";echo Core\Str::join(Core\Path::split('etc//hosts/'), ','), ' ', Core\Path::isAbsolute('C:/tmp') ? 'abs' : 'rel', ' ', Core\Path::isAbsolute('tmp') ? 'abs' : 'rel', "\n";echo Core\Path::extension('Makefile') ?? 'none', "\n";echo Core\Path::matches('*.jpg', 'photos/2024/beach.jpg') ? 'yes' : 'no', ' ', Core\Path::matches('src/*.nvs', 'lib/src/app.nvs') ? 'yes' : 'no', "\n";index.php index php/var/www/html /var/www/var/www/html/index.html/var/www/html/index.php/var/log/app.log../log/app.logetc,hosts abs relnoneyes noMembers
13 members.
| Member | Signature |
|---|---|
fileName | fileName(string $path, { withoutExtension?: bool }): string |
parent | parent(string $path, { levels?: uint }): string |
extension | extension(string $path): ?string |
withExtension | withExtension(string $path, ?string $extension): string |
join | join(string $base, string ...$segments): string |
split | split(string $path): array<string> |
normalize | normalize(string $path): string |
isAbsolute | isAbsolute(string $path): bool |
matches | matches(string $pattern, string $path): bool |
relativeTo | relativeTo(string $path, string $base): ?string |
fromWorkingDirectory | fromWorkingDirectory(string $path): string |
thisFile | thisFile(): string |
thisDirectory | thisDirectory(?string $join = null): string |
Constants
Core\Path::SEPARATORThe path separator of this platform. It is\on Windows and/on every other platform. Every method writes it, and every method accepts both/and\.
