]> git.tdb.fi Git - libs/core.git/blob - source/fs/utils.h
Style update: remove alignment
[libs/core.git] / source / fs / utils.h
1 #ifndef MSP_FS_UTILS_H_
2 #define MSP_FS_UTILS_H_
3
4 #include "path.h"
5
6 namespace Msp {
7 namespace FS {
8
9 /// Extracts the last component of the path.
10 std::string basename(const Path &);
11
12 /// Removes the last component from the path.
13 Path dirname(const Path &);
14
15 /**
16 Returns the base part of a filename.  This includes everything up to the last
17 dot, but not the dot itself.
18 */
19 std::string basepart(const std::string &);
20
21 /**
22 Returns the extension part of a filename.  This includes the last dot and
23 everything after it.
24 */
25 std::string extpart(const std::string &);
26
27 /**
28 Fixes the case of the given path to match files / directories on the
29 filesystem.
30 */
31 Path fix_case(const Path &path);
32
33 /// Reads the contents of a symbolic link
34 Path readlink(const Path &path);
35
36 /// Resolves all symlinks from a path.  Will always return an absolute path.
37 Path realpath(const Path &path);
38
39 /// Removes a file
40 void unlink(const Path &path);
41
42 /// Renames a file.  Existing file, if any, is overwritten.
43 void rename(const Path &from, const Path &to);
44
45 /// Makes a path relative to some base path.  That is, base/result==path.
46 Path relative(const Path &path, const Path &base);
47
48 /** Determines how many levels a path is below another.  Returns -1 if path is
49 not a descendant of parent. */
50 int descendant_depth(const Path &path, const Path &parent);
51
52 } // namespace FS
53 } // namespace Msp
54
55 #endif