SbFileHelper Class Reference

VSG extension Utilities class for file management. More...

#include <Inventor/helpers/SbFileHelper.h>

List of all members.

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)

Detailed Description

VSG extension 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.

See related examples:

BatchProcessing


Member Typedef Documentation

typedef struct stat64 SbFileHelper::Stat [read]

Member Enumeration Documentation

File access mode enum.

Enumerator:
EXISTENCE 

Check file for existence only.

WRITE 

Check file for Write access only.

READ 

Check file for Read access only.

READ_WRITE 

Check file for Read and Write access.

EXECUTE 

Check file for Execution access.


Member Function Documentation

static SbString SbFileHelper::cleanUpPath ( const SbString path  )  [static]

Removes all multiple occurences of '/' in the path.

static void SbFileHelper::close ( FILE *  fp  )  [static]

Close a file opened using the open function.

Parameters:
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.

Parameters:
directory The path of the directory to create.
Returns:
-1 if creation failed.
static SbString SbFileHelper::expandString ( const SbString string  )  [static]

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.

static SbString SbFileHelper::fileSystemURLToFilename ( const SbString url  )  [static]

Converts a file system URL to a regular filename
E.g "file:///c:/temp/test.dat" becomes "c:/temp/test.dat".

Parameters:
url The URL to convert.
Returns:
The converted filename.
static SbString SbFileHelper::getBaseName ( const SbString fullFilePath  )  [static]

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"

Parameters:
fullFilePath The full path string
Returns:
The extracted filename
static SbString SbFileHelper::getCurrentDirectory (  )  [static]

Returns the current directory.

static SbString SbFileHelper::getDirName ( const SbString fullFilePath  )  [static]

Returns the directory path part of a full path string.


E.g. If the full path is "/tmp/a.tmp", returns "/tmp/"

Parameters:
fullFilePath The full path string
Returns:
The directory path string
static SbString SbFileHelper::getExtension ( const SbString filename  )  [static]

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:

  • The file size in bytes.
  • The access information.
  • The creation/modification time.
Parameters:
filename The full path to the file.
stat The stat structure filled with the information about the file.
Returns:
True if successful.
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.

Parameters:
path The path to the directory which will contain the file (see getTempDirectory()).
prefix The filename prefix.
Returns:
A temporary filename.
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.

Parameters:
filename The file to test.
mode The file access mode
Returns:
TRUE if the file is accessible, FALSE otherwise.
static SbBool SbFileHelper::isFileSystemUrl ( const SbString filename  )  [static]

Returns TRUE if the filename is a file system URL like: file://.

..

static SbBool SbFileHelper::isUrl ( const SbString filename  )  [static]

Returns TRUE if the filename is a network url like: http:// or ftp://.

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.

Parameters:
[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 );
static SbString SbFileHelper::makeFileSystemURL ( const SbString filename  )  [static]

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.

Parameters:
filename The file name to convert
Returns:
The converted filename.
static FILE* SbFileHelper::open ( const SbString filename,
const char *  flags 
) [static]

Open a file and return a handle to it.

Parameters:
filename The filename (can be Latin-1/ASCII or unicode).
flags Regular flags used by fopen system call.
Returns:
Returns a handle to the file.
static int SbFileHelper::removeFile ( const SbString fileName  )  [static]

Removes the specified file.

Parameters:
fileName The file to remove.
Returns:
An error code, 0 if there was no error.
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.

static SbString SbFileHelper::toUnixPath ( const SbString path  )  [static]

Converts a Microsoft Windows path (with '\') to a Unix path (with '/').


A leading "\\" (used for network paths) is not converted.

Parameters:
path The path to convert.
Returns:
The converted path
static SbString SbFileHelper::toWindowsPath ( const SbString path  )  [static]

Converts a Unix path (with '/') to a Microsoft Windows path (with '\').

Parameters:
path The path to convert.
Returns:
The converted path

The documentation for this class was generated from the following file:

Open Inventor Toolkit reference manual, generated on 15 Mar 2023
Copyright © Thermo Fisher Scientific All rights reserved.
http://www.openinventor.com/