Utilities class for file management. More...
#include <Inventor/helpers/SbFileHelper.h>
Public Types | |
enum | FileAccess { EXISTENCE = F_OK, WRITE = W_OK, READ = R_OK, READ_WRITE = W_OK + R_OK, EXECUTE = X_OK } |
typedef struct stat64 | Stat |
Static Public Member Functions | |
static FILE * | open (const SbString &filename, const char *flags) |
static void | close (FILE *fp) |
static unsigned long long | getFileSize (const SbString &filename) |
static SbBool | isAccessible (const SbString &filename, FileAccess mode=READ) |
static SbString | getExtension (const SbString &filename) |
static SbBool | isUrl (const SbString &filename) |
static SbBool | isFileSystemUrl (const SbString &filename) |
static SbString | makeFileSystemURL (const SbString &filename) |
static SbString | fileSystemURLToFilename (const SbString &url) |
static SbString | getBaseName (const SbString &fullFilePath) |
static SbString | getDirName (const SbString &fullFilePath) |
static SbString | toUnixPath (const SbString &path) |
static SbString | toWindowsPath (const SbString &path) |
static SbString | getTempDirectory () |
static SbString | getTempFilename (const SbString &path, const SbString &prefix) |
static int | createDirectory (const SbString &directory) |
static SbString | getCurrentDirectory () |
static int | setCurrentDirectory (const SbString &directory) |
static bool | containsWindowsDrive (const SbString &path) |
static int | removeFile (const SbString &fileName) |
static bool | getStat (const SbString &filename, SbFileHelper::Stat &stat) |
static SbString | cleanUpPath (const SbString &path) |
static SbString | expandString (const SbString &string) |
static void | listFiles (const SbString &path, const SbString &pattern, std::vector< SbString > &files) |
Portable utility functions to manage files and manage file path strings.
File path strings can contain SoPreference (environment) variable names preceded by the '$' (dollar sign) character. These names are expanded to their defined value before passing the string to the operating system. For example, "$OIVHOME/data/models/bird.iv" could be used to access a file installed by the Open Inventor SDK. If the specified name does not have a defined value, the name is used as-is.
typedef struct stat64 SbFileHelper::Stat [read] |
Removes all multiple occurences of '/' in the path.
static void SbFileHelper::close | ( | FILE * | fp | ) | [static] |
Close a file opened using the open function.
fp | The handle of the file to be closed. |
static bool SbFileHelper::containsWindowsDrive | ( | const SbString & | path | ) | [static] |
Returns true if the specified path starts with a Microsoft Windows drive letter.
static int SbFileHelper::createDirectory | ( | const SbString & | directory | ) | [static] |
Create the specified directory.
directory | The path of the directory to create. |
Returns a new version of the string with "$NAME" SoPreference variable names expanded to their defined value.
If the specified name does not have a defined value, the name is copied as-is.
Converts a file system URL to a regular filename
E.g "file:///c:/temp/test.dat" becomes "c:/temp/test.dat".
url | The URL to convert. |
Returns the filename part of a full path string.
E.g If the full path is "/tmp/a.tmp", the function will return "a.tmp"
fullFilePath | The full path string |
static SbString SbFileHelper::getCurrentDirectory | ( | ) | [static] |
Returns the current directory.
Returns the directory path part of a full path string.
E.g. If the full path is "/tmp/a.tmp", returns "/tmp/"
fullFilePath | The full path string |
Returns the extension part of the specified filename.
It does not include the '.' used to separate the file name and the extension!
E.g. If the filename is "test.dat", the function returns "dat".
static unsigned long long SbFileHelper::getFileSize | ( | const SbString & | filename | ) | [static] |
Returns the size of the specified file in bytes.
static bool SbFileHelper::getStat | ( | const SbString & | filename, | |
SbFileHelper::Stat & | stat | |||
) | [static] |
This function fills the stat structure with information about the specified file.
The stat structure contains the following entries:
filename | The full path to the file. | |
stat | The stat structure filled with the information about the file. |
static SbString SbFileHelper::getTempDirectory | ( | ) | [static] |
Returns the path to the temporary directory used by the system.
Useful with the getTempFilename() method. The path ends with an operating system dependent directory separator.
static SbString SbFileHelper::getTempFilename | ( | const SbString & | path, | |
const SbString & | prefix | |||
) | [static] |
Returns a temporary filename.
path | The path to the directory which will contain the file (see getTempDirectory()). | |
prefix | The filename prefix. |
static SbBool SbFileHelper::isAccessible | ( | const SbString & | filename, | |
FileAccess | mode = READ | |||
) | [static] |
Returns TRUE if a file is accessible
.
The default value of the mode parameter is READ_ONLY.
Note that this method cannot be used to test if it is possible to create a file for writing. It only works on existing files.
filename | The file to test. | |
mode | The file access mode |
Returns TRUE if the filename is a file system URL like: file://.
..
static void SbFileHelper::listFiles | ( | const SbString & | path, | |
const SbString & | pattern, | |||
std::vector< SbString > & | files | |||
) | [static] |
Returns a list of the files in directory 'path' that match a 'pattern' Pattern may include the basic wild card characters: '*' matches anything and '?' matches any single character.
The file names are sorted by time of last access (stat.st_atime) with newest files first.
On Microsoft Windows systems, note:
Since Windows NT, updates to time of last access on NTFS file systems are disabled by default. So normally the access time is the same as the creation time and effectively the file names are sorted by creation time. It is possible to change the file system behavior, see Microsoft documentation.
[in] | path | The path to the directory where the files are located |
[in] | pattern | The string to match against the name of files in path. |
[out] | files | The list of files matching the pattern in path. |
Example:
std::vector<SbString> files; listFiles( "C:/my/path", "*.tif", files );
Converts a filename to a file system URL.
Actually it just adds the string file:// to the filename, if and only if the filename is not already a file system URL.
filename | The file name to convert |
static FILE* SbFileHelper::open | ( | const SbString & | filename, | |
const char * | flags | |||
) | [static] |
Open a file and return a handle to it.
filename | The filename (can be Latin-1/ASCII or unicode). | |
flags | Regular flags used by fopen system call. |
static int SbFileHelper::removeFile | ( | const SbString & | fileName | ) | [static] |
Removes the specified file.
fileName | The file to remove. |
static int SbFileHelper::setCurrentDirectory | ( | const SbString & | directory | ) | [static] |
Sets the current working directory.
Returns 0 if successful, else one of the POSIX "chdir" error codes.
Converts a Microsoft Windows path (with '\') to a Unix path (with '/').
A leading "\\" (used for network paths) is not converted.
path | The path to convert. |
Converts a Unix path (with '/') to a Microsoft Windows path (with '\').
path | The path to convert. |