All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
33TF_API
34bool TfPathExists(std::string const& path, bool resolveSymlinks = false);
35
46TF_API
47bool TfIsDir(std::string const& path, bool resolveSymlinks = false);
48
59TF_API
60bool TfIsFile(std::string const& path, bool resolveSymlinks = false);
61
69TF_API
70bool TfIsLink(std::string const& path);
71
79TF_API
80bool TfIsWritable(std::string const& path);
81
83TF_API
84bool TfIsDirEmpty(std::string const& path);
85
87TF_API
88bool TfSymlink(std::string const& src, std::string const& dst);
89
91TF_API
92bool TfDeleteFile(std::string const& path);
93
100TF_API
101bool TfMakeDir(std::string const& path, int mode=-1);
102
110TF_API
111bool TfMakeDirs(std::string const& path, int mode=-1, bool existOk=false);
112
125typedef std::function<bool (std::string const&,
126 std::vector<std::string> *,
127 std::vector<std::string> const&)> TfWalkFunction;
128
134typedef std::function<void (std::string const&,
135 std::string const&)> TfWalkErrorHandler;
136
142TF_API
143void TfWalkIgnoreErrorHandler(std::string const& path, std::string const& msg);
144
183TF_API
184void TfWalkDirs(std::string const& top,
186 bool topDown=true,
187 TfWalkErrorHandler onError = 0,
188 bool followLinks = false);
189
197TF_API
198void TfRmTree(std::string const& path,
199 TfWalkErrorHandler onError = 0);
200
206TF_API
207std::vector<std::string> TfListDir(std::string const& path,
208 bool recursive = false);
209
220TF_API
221bool
222TfReadDir(std::string const &dirPath,
223 std::vector<std::string> *dirnames,
224 std::vector<std::string> *filenames,
225 std::vector<std::string> *symlinknames,
226 std::string *errMsg = NULL);
227
235TF_API
236bool TfTouchFile(std::string const &fileName, bool create=true);
237
238PXR_NAMESPACE_CLOSE_SCOPE
239
240#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:135
std::function< bool(std::string const &, std::vector< std::string > *, std::vector< std::string > const &)> TfWalkFunction
Function type for TfWalkDirs.
Definition: fileUtils.h:127
TF_API bool TfMakeDir(std::string const &path, int mode=-1)
Creates a directory.