The Path module in Crystal provides functions to parse and construct file paths in a way that is portable between operating systems; dir/file on Linux vs. dir\file on Windows, for example.
To run the program, save it as file_paths.cr and use the crystal command:
The Crystal Path module provides similar functionality to Go’s filepath package. It allows for portable path manipulation across different operating systems. The Path[] method is used to construct paths, similar to filepath.Join in Go. Methods like dirname, basename, absolute?, extension, and stem correspond to similar functions in Go’s filepath package.
The relative_to? method in Crystal is analogous to filepath.Rel in Go, but it returns nil instead of an error when a relative path cannot be constructed.
Note that Crystal’s Path module doesn’t have a direct equivalent to Go’s filepath.Split. However, you can achieve the same result by using dirname and basename separately.