Skip to content

Filepath

Spice
import "std/io/filepath";

FilePath struct

Represents a path to a file or directory on the local file system

Constructors

ctor

Spice
public p FilePath.ctor()

Construct an empty file path

ctor

Spice
public p FilePath.ctor(string pathStr)

Construct a file path from a raw string

Parameters

Name Type Description
pathStr string Path string

ctor

Spice
public p FilePath.ctor(const String& pathStr)

Construct a file path from a String

Parameters

Name Type Description
pathStr const String& Path string

Methods

replaceSeparator

Spice
public p FilePath.replaceSeparator(char separator)

Replace every path separator in the path with the given one

Parameters

Name Type Description
separator char Separator to use

makeGeneric

Spice
public inline p FilePath.makeGeneric()

Convert the path to use the generic (UNIX) path separator

makeNative

Spice
public inline p FilePath.makeNative()

Convert the path to use the native path separator of the current platform

isEmpty

Spice
public inline f<bool> FilePath.isEmpty()

Checks if the filepath is empty

Returns: bool — Is the filepath empty

toString

Spice
public inline f<string> FilePath.toString()

Returns the content of the filepath without modifying.

Returns: string — The content of the filepath

toGenericString

Spice
public inline f<string> FilePath.toGenericString()

Returns the content of the filepath using the UNIX path separator.

Returns: string — The content of the filepath using the UNIX path separator

toNativeString

Spice
public inline f<string> FilePath.toNativeString()

Returns the content of the filepath using the native path separator.

Returns: string — The content of the filepath using the native path separator

getFileName

Spice
public inline f<String> FilePath.getFileName()

Returns the parent directory of the file or directory.

Example:
In: /home/user/file.txt
Out: file.txt

Returns: String — The parent directory of the file or directory

getParentDir

Spice
public inline f<String> FilePath.getParentDir()

Returns the parent directory of the file or directory.

Example:
In: /home/user/file.txt
Out: /home/user

Returns: String — The parent directory of the file or directory

getBaseName

Spice
public inline f<String> FilePath.getBaseName()

Returns the base name of the file.

Example:
In: /home/user/file.txt
Out: file

Returns: String — The base name of the file

getExtension

Spice
public inline f<String> FilePath.getExtension()

Returns the extension of the file.

Example:
In: /home/user/file.txt
Out: txt

Returns: String — The extension of the file

replaceExtension

Spice
public inline p FilePath.replaceExtension(string newExtension)

Replaces the current file extension with the given new one

Example:
In: /home/user/file.txt
Out: /home/user/file.spice

Parameters

Name Type Description
newExtension string New file extension

exists

Spice
public inline f<bool> FilePath.exists()

Checks if the file or directory exists.

Returns: bool — True if the file or directory exists, false otherwise

Operators

operator==

Spice
public inline f<bool> operator==(const FilePath& lhs, const FilePath& rhs)

Check if two file paths are equal

Parameters

Name Type Description
lhs const FilePath&
rhs const FilePath&

Returns: bool — Equal or not equal

operator!=

Spice
public inline f<bool> operator!=(const FilePath& lhs, const FilePath& rhs)

Check if two file paths are not equal

Parameters

Name Type Description
lhs const FilePath&
rhs const FilePath&

Returns: bool — Not equal or equal

operator/=

Spice
public p operator/=(FilePath& lhs, string rhs)

Append a path component to the path, inserting a separator if needed

Parameters

Name Type Description
lhs FilePath&
rhs string Path component to append

operator/=

Spice
public inline p operator/=(FilePath& lhs, const String& rhs)

Append a path component to the path, inserting a separator if needed

Parameters

Name Type Description
lhs FilePath&
rhs const String& Path component to append

operator/=

Spice
public inline p operator/=(FilePath& lhs, const FilePath& rhs)

Append a path component to the path, inserting a separator if needed

Parameters

Name Type Description
lhs FilePath&
rhs const FilePath& Path component to append

operator/

Spice
public inline f<FilePath> operator/(const FilePath& lhs, string rhs)

Join a path and a path component into a new file path, inserting a separator if needed

Parameters

Name Type Description
lhs const FilePath&
rhs string

Returns: FilePath — New joined file path

operator/

Spice
public inline f<FilePath> operator/(const FilePath& lhs, const String& rhs)

Join a path and a path component into a new file path, inserting a separator if needed

Parameters

Name Type Description
lhs const FilePath&
rhs const String&

Returns: FilePath — New joined file path

operator/

Spice
public inline f<FilePath> operator/(const FilePath& lhs, const FilePath& rhs)

Join two file paths into a new file path, inserting a separator if needed

Parameters

Name Type Description
lhs const FilePath&
rhs const FilePath&

Returns: FilePath — New joined file path