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 TF_FILEUTILS_H
25 #define TF_FILEUTILS_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 
104 TF_API
105 bool TfMakeDirs(std::string const& path, int mode=-1);
106 
119 typedef std::function<bool (std::string const&,
120  std::vector<std::string> *,
121  std::vector<std::string> const&)> TfWalkFunction;
122 
128 typedef std::function<void (std::string const&,
129  std::string const&)> TfWalkErrorHandler;
130 
136 TF_API
137 void TfWalkIgnoreErrorHandler(std::string const& path, std::string const& msg);
138 
177 TF_API
178 void TfWalkDirs(std::string const& top,
179  TfWalkFunction fn,
180  bool topDown=true,
181  TfWalkErrorHandler onError = 0,
182  bool followLinks = false);
183 
191 TF_API
192 void TfRmTree(std::string const& path,
193  TfWalkErrorHandler onError = 0);
194 
200 TF_API
201 std::vector<std::string> TfListDir(std::string const& path,
202  bool recursive = false);
203 
214 TF_API
215 bool
216 TfReadDir(std::string const &dirPath,
217  std::vector<std::string> *dirnames,
218  std::vector<std::string> *filenames,
219  std::vector<std::string> *symlinknames,
220  std::string *errMsg = NULL);
221 
229 TF_API
230 bool TfTouchFile(std::string const &fileName, bool create=true);
231 
232 PXR_NAMESPACE_CLOSE_SCOPE
233 
234 #endif // TF_FILEUTILS_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.
TF_API bool TfMakeDirs(std::string const &path, int mode=-1)
Creates a directory hierarchy.
std::function< bool(std::string const &, std::vector< std::string > *, std::vector< std::string > const &)> TfWalkFunction
Function type for TfWalkDirs.
Definition: fileUtils.h:121
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:129
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 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.