Jetson Inference
DNN Vision Library
filesystem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __FILESYSTEM_UTIL_H__
24 #define __FILESYSTEM_UTIL_H__
25 
26 #include <string>
27 #include <vector>
28 
29 
30 
43 std::string absolutePath( const std::string& relative_path );
44 
56 std::string locateFile( const std::string& path );
57 
67 std::string locateFile( const std::string& path, std::vector<std::string>& locations );
68 
77 std::string readFile( const std::string& path );
78 
84 std::string pathJoin( const std::string& a, const std::string& b );
85 
91 std::string pathDir( const std::string& path );
92 
97 std::string pathFilename( const std::string& path );
98 
104 std::pair<std::string, std::string> splitPath( const std::string& path );
105 
111 {
113  FILE_REGULAR = (1 << 0),
114  FILE_DIR = (1 << 1),
115  FILE_LINK = (1 << 2),
116  FILE_CHAR = (1 << 3),
117  FILE_BLOCK = (1 << 4),
118  FILE_FIFO = (1 << 5),
119  FILE_SOCKET = (1 << 6)
120 };
121 
136 bool listDir( const std::string& path, std::vector<std::string>& list, uint32_t mask=0 );
137 
146 bool fileExists( const std::string& path, uint32_t mask=0 );
147 
154 bool fileIsType( const std::string& path, uint32_t mask );
155 
161 uint32_t fileType( const std::string& path );
162 
172 size_t fileSize( const std::string& path );
173 
180 std::string fileExtension( const std::string& path );
181 
187 bool fileHasExtension( const std::string& path, const std::string& extension );
188 
193 bool fileHasExtension( const std::string& path, const std::vector<std::string>& extensions );
194 
201 bool fileHasExtension( const std::string& path, const char** extensions );
202 
209 std::string fileRemoveExtension( const std::string& filename );
210 
217 std::string fileChangeExtension( const std::string& filename, const std::string& newExtension );
218 
219 
220 #endif
221 
fileExists
bool fileExists(const std::string &path, uint32_t mask=0)
Return the directory /** Verify path and return true if the file exists.
FILE_REGULAR
@ FILE_REGULAR
Definition: filesystem.h:113
pathFilename
std::string pathFilename(const std::string &path)
Return the filename from the path, including the file extension.
FILE_BLOCK
@ FILE_BLOCK
Definition: filesystem.h:117
fileIsType
bool fileIsType(const std::string &path, uint32_t mask)
Return true if the file is one of the types in the fileTypes mask.
splitPath
std::pair< std::string, std::string > splitPath(const std::string &path)
Split a path into directory and filename components.
fileChangeExtension
std::string fileChangeExtension(const std::string &filename, const std::string &newExtension)
Return the input string with a changed file extension For example, fileChangeExtension("~/workspace/s...
FILE_FIFO
@ FILE_FIFO
Definition: filesystem.h:118
pathJoin
std::string pathJoin(const std::string &a, const std::string &b)
Join two paths, and properly include a path separator (/) as needed.
FILE_MISSING
@ FILE_MISSING
Definition: filesystem.h:112
FILE_SOCKET
@ FILE_SOCKET
Definition: filesystem.h:119
fileSize
size_t fileSize(const std::string &path)
Return the size (in bytes) of the specified file.
FILE_CHAR
@ FILE_CHAR
Definition: filesystem.h:116
FILE_LINK
@ FILE_LINK
Definition: filesystem.h:115
pathDir
std::string pathDir(const std::string &path)
Return the parent directory of the specified path, removing the filename and extension.
absolutePath
std::string absolutePath(const std::string &relative_path)
Given a relative path, resolve the absolute path using the working directory.
fileType
uint32_t fileType(const std::string &path)
Return the file type, or FILE_MISSING if it doesn't exist.
fileRemoveExtension
std::string fileRemoveExtension(const std::string &filename)
Return the input string with the file extension removed For example, fileRemoveExtension("~/workspace...
FILE_DIR
@ FILE_DIR
Definition: filesystem.h:114
locateFile
std::string locateFile(const std::string &path)
Locate a file from common system locations.
fileHasExtension
bool fileHasExtension(const std::string &path, const std::string &extension)
Return true if the file has the given extension, otherwise false.
readFile
std::string readFile(const std::string &path)
Read a text file into a string.
fileExtension
std::string fileExtension(const std::string &path)
Extract the file extension from the path.
listDir
bool listDir(const std::string &path, std::vector< std::string > &list, uint32_t mask=0)
Return a sorted list of the files in the specified directory.
fileTypes
fileTypes
File types.
Definition: filesystem.h:110