19 namespace filesystem {
22 template <
typename... T>
25 if (
sizeof...(paths) == 1) {
26 int unpack[]{0, (
result = std::string(paths), 0)...};
27 static_cast<void>(unpack);
32 :
result +
"/" + std::string(paths),
34 static_cast<void>(unpack);
59 JoinPath(
const std::vector<std::string> &path_components);
62 const std::string &path_component2);
89 const std::string &ext);
114 const std::string &dst_path);
124 const std::string &to,
125 bool include_parent_dir =
false,
126 const std::string &extname =
"");
183 std::vector<std::string> &subdirs,
184 std::vector<std::string> &filenames);
187 std::vector<std::string> &filenames);
191 const std::string &extname,
192 std::vector<std::string> &filenames);
195 const std::string &directory,
196 std::function<
bool(
const std::string &)> is_match);
200 const std::string &mode);
203 std::vector<char> &
bytes,
204 std::string *errorStr);
207 const std::string &
path,
const std::vector<std::string> &folder_names);
225 bool Open(
const std::string &
filename,
const std::string &mode);
228 std::string GetError();
237 int64_t GetFileSize();
240 int64_t GetNumLines();
246 const char *ReadLine();
254 return ReadData(data,
sizeof(T), num_elems);
261 size_t ReadData(
void *data,
size_t elem_size,
size_t num_elems);
267 FILE *file_ =
nullptr;
269 std::vector<char> line_buffer_;
FILE * GetFILE()
Returns the underlying C FILE pointer.
size_t ReadData(T *data, size_t num_elems)
Helper functions for the ml ops.
static const std::string path
bool ChangeWorkingDirectory(const std::string &directory)
bool ListFilesInDirectory(const std::string &directory, std::vector< std::string > &filenames)
bool RemoveFile(const std::string &filename)
std::string GetWorkingDirectory()
std::vector< std::string > FindFilesRecursively(const std::string &directory, std::function< bool(const std::string &)> is_match)
bool IsDirectory(const std::string &directory)
std::string EnsureTrailingSlash(const std::string &str)
bool DeleteDirectory(const std::string &directory)
bool Copy(const std::string &from, const std::string &to, bool include_parent_dir=false, const std::string &extname="")
Copy a file or directory.
bool FReadToBuffer(const std::string &path, std::vector< char > &bytes, std::string *errorStr)
bool MakeDirectoryHierarchy(const std::string &directory)
bool CopyFile(const std::string &from, const std::string &to)
Copy a file.
bool DirectoryIsEmpty(const std::string &directory)
std::string GetFileParentDirectory(const std::string &filename)
std::string GetEnvVar(const std::string &env_var)
bool ListFilesInDirectoryWithExtension(const std::string &directory, const std::string &extname, std::vector< std::string > &filenames)
void SplitFileExtension(const std::string &path, std::string *root, std::string *ext)
std::string GetTempDirectoryPath()
bool DirectoryExists(const std::string &directory)
std::string JoinPath(const std::vector< std::string > &path_components)
std::string GetIOErrorString(const int errnoVal)
std::string GetFileBaseName(const std::string &filename)
bool CopyDir(const std::string &from, const std::string &to)
Copy a directory.
bool EnsureDirectory(const std::string &directory_path)
Check if a specified directory specified by directory_path exists. If not, recursively create the dir...
std::string GetRegularizedDirectoryName(const std::string &directory)
std::string GetFileNameWithoutExtension(const std::string &filename)
std::string GetFileExtensionInLowerCase(const std::string &filename)
bool FileExists(const std::string &filename)
bool IsFile(const std::string &filename)
std::string JoinPaths(T const &...paths)
std::vector< std::string > GetPathComponents(const std::string &path)
bool MakeDirectory(const std::string &directory)
FILE * FOpen(const std::string &filename, const std::string &mode)
std::string AddIfExist(const std::string &path, const std::vector< std::string > &folder_names)
bool HasFileExtension(const std::string &file_name, const std::string &ext)
std::string GetHomeDirectory()
Get the HOME directory for the user.
std::string GetFileNameWithoutDirectory(const std::string &filename)
bool CopyA(const std::string &src_path, const std::string &dst_path)
bool ListDirectory(const std::string &directory, std::vector< std::string > &subdirs, std::vector< std::string > &filenames)
bool StringEndsWith(const std::string &str, const std::string &postfix)
std::string StringReplaceLast(const std::string &str, const std::string &old_str, const std::string &new_str)
bool StringContains(const std::string &src, const std::string &dst)
std::string StringReplace(const std::string &str, const std::string &old_str, const std::string &new_str)
Generic file read and write utility for python interface.