struct Path


A Path represents a filesystem path and allows path-handling operations such as querying its components as well as semantic manipulations.

A path is hierarchical and composed of a sequence of directory and file name elements separated by a special separator or delimiter. A root component, that identifies a file system hierarchy, may also be present. The name element that is farthest from the root of the directory hierarchy is the name of a file or directory. The other name elements are directory names. A Path can represent a root, a root and a sequence of names, or simply one or more name elements. A Path is considered to be an empty path if it consists solely of one name element that is empty or equal to ".". Accessing a file using an empty path is equivalent to accessing the default directory of the process.


Path["foo/bar/"].parent    # => Path["foo/bar"]
Path["foo/bar/"].basename  # => ""
Path["./foo/../bar"].normalize   # => Path["bar"]
Path["~/bin"].expand(home: true) # => Path["/home/crystal/bin"]

For now, its methods are purely lexical, there is no direct filesystem access.

Path handling comes in different kinds depending on operating system:

# On POSIX system:"foo", "bar", "") == Path.posix("foo/bar/")
# On Windows system:"foo", "bar", "") =="foo\\bar\\")

The main differences between Windows and POSIX paths:

Path.posix("/foo/./bar").normalize   # => Path.posix("/foo/bar")"/foo/./bar").normalize # =>"\\foo\\bar")

Path.posix("/foo").absolute?   # => true"/foo").absolute? # => false

Path.posix("foo") == Path.posix("FOO")     # => false"foo") =="FOO") # => true

Included Modules

Defined in:


Class Method Summary

Instance Method Summary

Class Method Detail

def self.g_type #

Returns the GObject GType for Path.

[View source]

Instance Method Detail

def to_unsafe(*args, **options) #

[View source]
def to_unsafe(*args, **options, &) #

[View source]