common_util
Loading...
Searching...
No Matches
filepath.h
Go to the documentation of this file.
1
19#pragma once
20
21#include <string>
22#include <iostream>
23#include <cstdio>
24#include "filetype.h"
25
26namespace cutl
27{
28
34 {
35 public:
41 filepath(const std::string &path);
42
48 filepath(const filepath &other);
49
56 filepath &operator=(const filepath &other);
57
62 ~filepath() = default;
63
64 public:
70 static char separator();
71
77 std::string str() const;
78
85 filepath join(const std::string &filename) const;
86
87 // file is exist or not
93 bool exists() const;
94
100 bool readable() const;
101
107 bool writable() const;
108
114 bool executable() const;
115
121 filetype type() const;
122
128 bool isfile() const;
129
135 bool isdir() const;
136
142 bool issymlink() const;
143
149 std::string dirname() const;
150
156 std::string basename() const;
164 std::string realpath() const;
170 std::string abspath() const;
176 std::string extension() const;
177
178 private:
179 std::string filepath_;
180 };
181
189 std::ostream &operator<<(std::ostream &os, const filepath &fp);
190
197 filepath path(const std::string &path);
198
199} // namespace cutl
The class for file path operations.
Definition filepath.h:34
filepath & operator=(const filepath &other)
Assign operator, assign a new filepath object by copy.
std::string abspath() const
Get the absolute path of the filepath.
bool isdir() const
Check if the filepath is a directory.
std::string extension() const
Get the extension of the filepath.
std::string realpath() const
Get the real path referenced by symbolic link.
bool exists() const
Check if the filepath is exists.
bool issymlink() const
Check if the filepath is a symbolic link.
static char separator()
Get the path separator of the current os platform.
std::string str() const
Get the string of the filepath.
filepath join(const std::string &filename) const
Join the current filepath with a new filename.
filepath(const std::string &path)
Construct a new filepath object.
filepath(const filepath &other)
Construct a new filepath object by copy.
std::string dirname() const
Get the parent directory of the filepath.
filetype type() const
Get the file type of the filepath.
std::string basename() const
Get the filename or directory name of the filepath.
bool executable() const
Check if the filepath is executable.
bool writable() const
Check if the filepath is writable.
bool isfile() const
Check if the filepath is a regular file.
bool readable() const
Check if the filepath is readable.
~filepath()=default
Destroy the filepath object.
std::ostream & operator<<(std::ostream &os, const datetime &dt)
Define the output stream operator for datetime object.
filepath path(const std::string &path)
Create a filepath object from a string.
Define the structs about fileutil, such as filetype and file_entity.
filetype
The type of file.
Definition filetype.h:38