Loading...
Searching...
No Matches
fileUtils.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_TF_FILE_UTILS_H
8#define PXR_BASE_TF_FILE_UTILS_H
9
13
14#include "pxr/pxr.h"
15#include "pxr/base/tf/api.h"
16
17#include <string>
18#include <vector>
19#include <functional>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
28TF_API
29bool TfPathExists(std::string const& path, bool resolveSymlinks = false);
30
36TF_API
37bool TfIsDir(std::string const& path, bool resolveSymlinks = false);
38
44TF_API
45bool TfIsFile(std::string const& path, bool resolveSymlinks = false);
46
48TF_API
49bool TfIsLink(std::string const& path);
50
58TF_API
59bool TfIsWritable(std::string const& path);
60
62TF_API
63bool TfIsDirEmpty(std::string const& path);
64
66TF_API
67bool TfSymlink(std::string const& src, std::string const& dst);
68
70TF_API
71bool TfDeleteFile(std::string const& path);
72
79TF_API
80bool TfMakeDir(std::string const& path, int mode=-1);
81
89TF_API
90bool TfMakeDirs(std::string const& path, int mode=-1, bool existOk=false);
91
104typedef std::function<bool (std::string const&,
105 std::vector<std::string> *,
106 std::vector<std::string> const&)> TfWalkFunction;
107
113typedef std::function<void (std::string const&,
114 std::string const&)> TfWalkErrorHandler;
115
121TF_API
122void TfWalkIgnoreErrorHandler(std::string const& path, std::string const& msg);
123
162TF_API
163void TfWalkDirs(std::string const& top,
165 bool topDown=true,
166 TfWalkErrorHandler onError = 0,
167 bool followLinks = false);
168
176TF_API
177void TfRmTree(std::string const& path,
178 TfWalkErrorHandler onError = 0);
179
185TF_API
186std::vector<std::string> TfListDir(std::string const& path,
187 bool recursive = false);
188
199TF_API
200bool
201TfReadDir(std::string const &dirPath,
202 std::vector<std::string> *dirnames,
203 std::vector<std::string> *filenames,
204 std::vector<std::string> *symlinknames,
205 std::string *errMsg = NULL);
206
214TF_API
215bool TfTouchFile(std::string const &fileName, bool create=true);
216
217PXR_NAMESPACE_CLOSE_SCOPE
218
219#endif // PXR_BASE_TF_FILE_UTILS_H
TF_API bool TfIsWritable(std::string const &path)
Returns true if the file or directory at path is writable.
TF_API bool TfIsFile(std::string const &path, bool resolveSymlinks=false)
Returns true if the path exists and is a file.
TF_API std::vector< std::string > TfListDir(std::string const &path, bool recursive=false)
Return a list containing files and directories in path.
TF_API bool TfReadDir(std::string const &dirPath, std::vector< std::string > *dirnames, std::vector< std::string > *filenames, std::vector< std::string > *symlinknames, std::string *errMsg=NULL)
Read the contents of dirPath and append the names of the contained directories, files,...
TF_API bool TfPathExists(std::string const &path, bool resolveSymlinks=false)
Returns true if the path exists.
TF_API bool TfSymlink(std::string const &src, std::string const &dst)
Creates a symbolic link from src to dst.
TF_API bool TfTouchFile(std::string const &fileName, bool create=true)
Touch fileName, updating access and modification time to 'now'.
TF_API bool TfIsDirEmpty(std::string const &path)
Returns true if the path is an empty directory.
TF_API void TfRmTree(std::string const &path, TfWalkErrorHandler onError=0)
Recursively delete a directory tree rooted at path.
TF_API void TfWalkIgnoreErrorHandler(std::string const &path, std::string const &msg)
error handler to use when you want to ignore errors
TF_API bool TfMakeDirs(std::string const &path, int mode=-1, bool existOk=false)
Creates a directory hierarchy.
TF_API bool TfDeleteFile(std::string const &path)
Deletes a file at path.
TF_API bool TfIsDir(std::string const &path, bool resolveSymlinks=false)
Returns true if the path exists and is a directory.
TF_API void TfWalkDirs(std::string const &top, TfWalkFunction fn, bool topDown=true, TfWalkErrorHandler onError=0, bool followLinks=false)
Directory tree walker.
TF_API bool TfIsLink(std::string const &path)
Returns true if the path exists and is a symbolic link.
std::function< void(std::string const &, std::string const &)> TfWalkErrorHandler
TfRmTree error handler function.
Definition: fileUtils.h:114
std::function< bool(std::string const &, std::vector< std::string > *, std::vector< std::string > const &)> TfWalkFunction
Function type for TfWalkDirs.
Definition: fileUtils.h:106
TF_API bool TfMakeDir(std::string const &path, int mode=-1)
Creates a directory.