All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fileUtils.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_BASE_TF_FILE_UTILS_H
25 #define PXR_BASE_TF_FILE_UTILS_H
26 
30 
31 #include "pxr/pxr.h"
32 #include "pxr/base/tf/api.h"
33 
34 #include <string>
35 #include <vector>
36 #include <functional>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
45 TF_API
46 bool TfPathExists(std::string const& path, bool resolveSymlinks = false);
47 
53 TF_API
54 bool TfIsDir(std::string const& path, bool resolveSymlinks = false);
55 
61 TF_API
62 bool TfIsFile(std::string const& path, bool resolveSymlinks = false);
63 
65 TF_API
66 bool TfIsLink(std::string const& path);
67 
75 TF_API
76 bool TfIsWritable(std::string const& path);
77 
79 TF_API
80 bool TfIsDirEmpty(std::string const& path);
81 
83 TF_API
84 bool TfSymlink(std::string const& src, std::string const& dst);
85 
87 TF_API
88 bool TfDeleteFile(std::string const& path);
89 
96 TF_API
97 bool TfMakeDir(std::string const& path, int mode=-1);
98 
106 TF_API
107 bool TfMakeDirs(std::string const& path, int mode=-1, bool existOk=false);
108 
121 typedef std::function<bool (std::string const&,
122  std::vector<std::string> *,
123  std::vector<std::string> const&)> TfWalkFunction;
124 
130 typedef std::function<void (std::string const&,
131  std::string const&)> TfWalkErrorHandler;
132 
138 TF_API
139 void TfWalkIgnoreErrorHandler(std::string const& path, std::string const& msg);
140 
179 TF_API
180 void TfWalkDirs(std::string const& top,
181  TfWalkFunction fn,
182  bool topDown=true,
183  TfWalkErrorHandler onError = 0,
184  bool followLinks = false);
185 
193 TF_API
194 void TfRmTree(std::string const& path,
195  TfWalkErrorHandler onError = 0);
196 
202 TF_API
203 std::vector<std::string> TfListDir(std::string const& path,
204  bool recursive = false);
205 
216 TF_API
217 bool
218 TfReadDir(std::string const &dirPath,
219  std::vector<std::string> *dirnames,
220  std::vector<std::string> *filenames,
221  std::vector<std::string> *symlinknames,
222  std::string *errMsg = NULL);
223 
231 TF_API
232 bool TfTouchFile(std::string const &fileName, bool create=true);
233 
234 PXR_NAMESPACE_CLOSE_SCOPE
235 
236 #endif // PXR_BASE_TF_FILE_UTILS_H
TF_API bool TfIsFile(std::string const &path, bool resolveSymlinks=false)
Returns true if the path exists and is a file.
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, and symlinks to dirnames, filenames, and symlinknames, respectively.
TF_API bool TfMakeDir(std::string const &path, int mode=-1)
Creates a directory.
std::function< bool(std::string const &, std::vector< std::string > *, std::vector< std::string > const &)> TfWalkFunction
Function type for TfWalkDirs.
Definition: fileUtils.h:123
TF_API bool TfSymlink(std::string const &src, std::string const &dst)
Creates a symbolic link from src to dst.
std::function< void(std::string const &, std::string const &)> TfWalkErrorHandler
TfRmTree error handler function.
Definition: fileUtils.h:131
TF_API bool TfIsLink(std::string const &path)
Returns true if the path exists and is a symbolic link.
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 TfDeleteFile(std::string const &path)
Deletes a file at path.
TF_API bool TfIsDirEmpty(std::string const &path)
Returns true if the path is an empty directory.
TF_API bool TfPathExists(std::string const &path, bool resolveSymlinks=false)
Returns true if the path exists.
TF_API bool TfMakeDirs(std::string const &path, int mode=-1, bool existOk=false)
Creates a directory hierarchy.
TF_API bool TfIsWritable(std::string const &path)
Returns true if the file or directory at path is writable.
TF_API bool TfIsDir(std::string const &path, bool resolveSymlinks=false)
Returns true if the path exists and is a directory.
TF_API void TfWalkIgnoreErrorHandler(std::string const &path, std::string const &msg)
error handler to use when you want to ignore errors
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 TfTouchFile(std::string const &fileName, bool create=true)
Touch fileName, updating access and modification time to &#39;now&#39;.
TF_API void TfRmTree(std::string const &path, TfWalkErrorHandler onError=0)
Recursively delete a directory tree rooted at path.