1 #ifndef MSP_FS_UTILS_H_
2 #define MSP_FS_UTILS_H_
4 #include <msp/core/mspcore_api.h>
10 /// Extracts the last component of the path.
11 MSPCORE_API std::string basename(const Path &);
13 /// Removes the last component from the path.
14 MSPCORE_API Path dirname(const Path &);
16 /** Returns the base part of a filename. This includes everything up to the
17 last dot, but not the dot itself. */
18 MSPCORE_API std::string basepart(const std::string &);
20 /** Returns the extension part of a filename. This includes the last dot and
21 everything after it. */
22 MSPCORE_API std::string extpart(const std::string &);
24 /// Fixes the case of a path to match files / directories on the filesystem.
25 MSPCORE_API Path fix_case(const Path &path);
27 /// Reads the contents of a symbolic link
28 MSPCORE_API Path readlink(const Path &path);
30 /// Resolves all symlinks from a path. Will always return an absolute path.
31 MSPCORE_API Path realpath(const Path &path);
34 MSPCORE_API void unlink(const Path &path);
36 /// Renames a file. Existing file, if any, is overwritten.
37 MSPCORE_API void rename(const Path &from, const Path &to);
39 /** Makes a path relative to some base path. That is, base/result==path. Both
40 paths must be either absolute or relative. */
41 MSPCORE_API Path relative(const Path &path, const Path &base);
43 /// Returns the longest prefix shared by both paths.
44 MSPCORE_API Path common_ancestor(const Path &, const Path &);
46 /** Determines how many levels a path is below another. Returns -1 if path is
47 not a descendant of parent. Both paths must be either absolute or relative. */
48 MSPCORE_API int descendant_depth(const Path &path, const Path &parent);