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 } |
File access mode enum. More... | |
typedef struct stat64 | Stat |
Static Public Member Functions | |
static FILE * | open (const SbString &filename, const char *flags) |
Open a file and return a handle to it. | |
static void | close (FILE *fp) |
Close a file opened using the open function. | |
static unsigned long long | getFileSize (const SbString &filename) |
Returns the size of the specified file in bytes. | |
static SbBool | isAccessible (const SbString &filename, FileAccess mode=READ) |
Returns TRUE if a file is accessible | |
static SbString | getExtension (const SbString &filename) |
Returns the extension part of the specified filename. | |
static SbBool | isUrl (const SbString &filename) |
Returns TRUE if the filename is a network url like: http:// or ftp://. | |
static SbBool | isFileSystemUrl (const SbString &filename) |
Returns TRUE if the filename is a file system URL like: file://... | |
static SbString | makeFileSystemURL (const SbString &filename) |
Converts a filename to a file system URL. | |
static SbString | fileSystemURLToFilename (const SbString &url) |
Converts a file system URL to a regular filename E.g "file:///c:/temp/test.dat" becomes "c:/temp/test.dat". | |
static SbString | getBaseName (const SbString &fullFilePath) |
Returns the filename part of a full path string. | |
static SbString | getDirName (const SbString &fullFilePath) |
Returns the directory path part of a full path string. | |
static SbString | toUnixPath (const SbString &path) |
Converts a Microsoft Windows path (with '\') to a Unix path (with '/'). | |
static SbString | toWindowsPath (const SbString &path) |
Converts a Unix path (with '/') to a Microsoft Windows path (with '\'). | |
static SbString | getTempDirectory () |
Returns the path to the temporary directory used by the system. | |
static SbString | getTempFilename (const SbString &path, const SbString &prefix) |
Returns a temporary filename. | |
static int | createDirectory (const SbString &directory) |
Create the specified directory. | |
static SbString | getCurrentDirectory () |
Returns the current directory. | |
static int | setCurrentDirectory (const SbString &directory) |
Sets the current working directory. | |
static bool | containsWindowsDrive (const SbString &path) |
Returns true if the specified path starts with a Microsoft Windows drive letter. | |
static int | removeFile (const SbString &fileName) |
Removes the specified file. | |
static bool | getStat (const SbString &filename, SbFileHelper::Stat &stat) |
This function fills the stat structure with information about the specified file. | |
static SbString | cleanUpPath (const SbString &path) |
Removes all multiple occurences of '/' in the path. | |
static SbString | expandString (const SbString &string) |
Returns a new version of the string with "$NAME" SoPreference variable names expanded to their defined value. | |
static void | listFiles (const SbString &path, const SbString &pattern, std::vector< SbString > &files) |
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. | |
Utilities class for file management.
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.
Definition at line 59 of file SbFileHelper.h.
typedef struct stat64 SbFileHelper::Stat |
Definition at line 66 of file SbFileHelper.h.
File access mode enum.
Definition at line 100 of file SbFileHelper.h.
Removes all multiple occurences of '/' in the path.
|
static |
Close a file opened using the open function.
fp | The handle of the file to be closed. |
|
static |
Returns true if the specified path starts with a Microsoft Windows drive letter.
|
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 |
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 |
Returns the size of the specified file in bytes.
|
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 |
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 |
Returns a temporary filename.
path | The path to the directory which will contain the file (see getTempDirectory()). |
prefix | The filename prefix. |
|
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 |
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:
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 |
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 |
Removes the specified file.
fileName | The file to remove. |
|
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. |