Loading...
Searching...
No Matches
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
38PXR_NAMESPACE_OPEN_SCOPE
39
45TF_API
46bool TfPathExists(std::string const& path, bool resolveSymlinks = false);
47
53TF_API
54bool TfIsDir(std::string const& path, bool resolveSymlinks = false);
55
61TF_API
62bool TfIsFile(std::string const& path, bool resolveSymlinks = false);
63
65TF_API
66bool TfIsLink(std::string const& path);
67
75TF_API
76bool TfIsWritable(std::string const& path);
77
79TF_API
80bool TfIsDirEmpty(std::string const& path);
81
83TF_API
84bool TfSymlink(std::string const& src, std::string const& dst);
85
87TF_API
88bool TfDeleteFile(std::string const& path);
89
96TF_API
97bool TfMakeDir(std::string const& path, int mode=-1);
98
106TF_API
107bool TfMakeDirs(std::string const& path, int mode=-1, bool existOk=false);
108
121typedef std::function<bool (std::string const&,
122 std::vector<std::string> *,
123 std::vector<std::string> const&)> TfWalkFunction;
124
130typedef std::function<void (std::string const&,
131 std::string const&)> TfWalkErrorHandler;
132
138TF_API
139void TfWalkIgnoreErrorHandler(std::string const& path, std::string const& msg);
140
179TF_API
180void TfWalkDirs(std::string const& top,
182 bool topDown=true,
183 TfWalkErrorHandler onError = 0,
184 bool followLinks = false);
185
193TF_API
194void TfRmTree(std::string const& path,
195 TfWalkErrorHandler onError = 0);
196
202TF_API
203std::vector<std::string> TfListDir(std::string const& path,
204 bool recursive = false);
205
216TF_API
217bool
218TfReadDir(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
231TF_API
232bool TfTouchFile(std::string const &fileName, bool create=true);
233
234PXR_NAMESPACE_CLOSE_SCOPE
235
236#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:131
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 TfMakeDir(std::string const &path, int mode=-1)
Creates a directory.