Vuo  1.2.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Static Public Member Functions | List of all members
VuoFileUtilities Class Reference

Description

Functions for dealing with files.

Classes

class  File
 A file in either a directory or an archive. More...
 

Static Public Member Functions

static void splitPath (string path, string &dir, string &file, string &extension)
 Splits path into its directory, file name, and file extension.
 
static string makeTmpFile (string file, string extension, string directory="/tmp")
 Creates a new temporary file, avoiding any name conflicts with existing files.
 
static string makeTmpDir (string dir)
 Creates a new temporary directory, avoiding any name conflicts with existing files.
 
static string makeTmpDirOnSameVolumeAsPath (string path)
 Creates a new temporary directory, avoiding any name conflicts with existing files.
 
static string getTmpDir (void)
 Returns the path of the default temporary directory.
 
static void makeDir (string path)
 Creates a new directory (and parent directories if needed), if it doesn't already exist.
 
static string getVuoFrameworkPath (void)
 Returns the absolute path of Vuo.framework (without a trailing slash), or an empty string if Vuo.framework cannot be located.
 
static string getUserModulesPath (void)
 Returns the filesystem path to the user-specific Vuo Modules folder (without a trailing slash).
 
static string getSystemModulesPath (void)
 Returns the filesystem path to the system-wide Vuo Modules folder (without a trailing slash).
 
static string getCachePath (void)
 Returns the filesystem path to the folder that Vuo uses to cache data (without a trailing slash).
 
static void preserveOriginalFileName (string &fileContents, string originalFileName)
 Saves originalFileName into fileContents so that, when fileContents is written to some other file path, originalFileName will still be the name that shows up in compile errors/warnings and in the FILE macro.
 
static size_t getFirstInsertionIndex (string s)
 Returns the first index at which content can be inserted into a string that was read from a file.
 
static string readStdinToString (void)
 Reads from standard input into a string until the end-of-file is reached.
 
static string readFileToString (string path)
 Reads the whole contents of the file into a string.
 
static void writeRawDataToFile (const char *data, size_t numBytes, string file)
 Writes the array of bytes to the file.
 
static void writeStringToFile (string s, string file)
 Writes the string to the file.
 
static bool fileExists (string path)
 Returns true if the file exists.
 
static bool dirExists (string path)
 Returns true if the file exists and is a directory.
 
static bool fileIsReadable (string path)
 Returns true if the file is readable.
 
static bool fileContainsReadableData (string path)
 Returns true if the file exists, can be opened, and has a size of more than 0 bytes.
 
static void createFile (string path)
 Creates the file if it does not exist already; otherwise, has no effect on the file.
 
static void deleteFile (string path)
 Deletes the file if it exists; otherwise, has no effect.
 
static void moveFile (string fromPath, string toPath)
 Moves the file from fromPath to toPath.
 
static void moveFileToTrash (string filePath)
 Moves the specified file to the user's trash folder.
 
static void copyFile (string fromPath, string toPath)
 Copies the file from fromPath to toPath.
 
static unsigned long getFileLastModifiedInSeconds (string path)
 Returns the time that the file was last modified, in seconds from a reference date.
 
static set< File * > findAllFilesInDirectory (string dirPath, set< string > archiveExtensions=set< string >(), bool shouldSearchRecursively=false)
 Searches a directory for files.
 
static set< File * > findFilesInDirectory (string dirPath, set< string > extensions, set< string > archiveExtensions=set< string >())
 Searches a directory for files with a given extension.
 
static set< File * > findAllFilesInArchive (string archivePath)
 Recursively searches an archive for files.
 
static set< File * > findFilesInArchive (string archivePath, string dirPath, set< string > extensions)
 Recursively searches an archive for files within a given directory and with a given extension.
 
static string getArchiveFileContentsAsString (string archivePath, string filePath)
 Returns the contents of a file within an archive.
 
static size_t getAvailableSpaceOnVolumeContainingPath (string path)
 Returns the available space, in bytes, on the volume containing the specified path.
 

Member Function Documentation

void VuoFileUtilities::copyFile ( string  fromPath,
string  toPath 
)
static

Copies the file from fromPath to toPath.

Exceptions
std::runtime_errorThe file couldn't be copied.
void VuoFileUtilities::createFile ( string  path)
static

Creates the file if it does not exist already; otherwise, has no effect on the file.

void VuoFileUtilities::deleteFile ( string  path)
static

Deletes the file if it exists; otherwise, has no effect.

bool VuoFileUtilities::dirExists ( string  path)
static

Returns true if the file exists and is a directory.

bool VuoFileUtilities::fileContainsReadableData ( string  path)
static

Returns true if the file exists, can be opened, and has a size of more than 0 bytes.

bool VuoFileUtilities::fileExists ( string  path)
static

Returns true if the file exists.

bool VuoFileUtilities::fileIsReadable ( string  path)
static

Returns true if the file is readable.

set< VuoFileUtilities::File * > VuoFileUtilities::findAllFilesInArchive ( string  archivePath)
static

Recursively searches an archive for files.

Parameters
archivePathThe archive to search in.
Returns
All files found.
set< VuoFileUtilities::File * > VuoFileUtilities::findAllFilesInDirectory ( string  dirPath,
set< string >  archiveExtensions = set<string>(),
bool  shouldSearchRecursively = false 
)
static

Searches a directory for files.

Parameters
dirPathThe directory to search in. Only the top level is searched.
archiveExtensionsThe file extensions for archives to search in. Any archive with one of these extensions found in the top level of the directory will be searched recursively.
shouldSearchRecursivelyIf true, the directory will be searched searched recursively.
Returns
All files found.
Exceptions
std::runtime_errorThe directory couldn't be read.
set< VuoFileUtilities::File * > VuoFileUtilities::findFilesInArchive ( string  archivePath,
string  dirPath,
set< string >  extensions 
)
static

Recursively searches an archive for files within a given directory and with a given extension.

Parameters
archivePathThe archive to search in.
dirPathThe directory to search in within the archive. The path should be relative to the archive's root. The path should omit the trailing file separator (e.g. "examples" not "examples/").
extensionsThe file extensions to search for, without the '.' character (e.g. "bc" not ".bc").
Returns
All files found.
set< VuoFileUtilities::File * > VuoFileUtilities::findFilesInDirectory ( string  dirPath,
set< string >  extensions,
set< string >  archiveExtensions = set<string>() 
)
static

Searches a directory for files with a given extension.

Parameters
dirPathThe directory to search in. Only the top level is searched.
archiveExtensionsThe file extensions for archives to search in. Any archive with one of these extensions found in the top level of the directory will be searched recursively.
extensionsThe file extensions to search for, without the '.' character (e.g. "bc" not ".bc").
Returns
All files found.
string VuoFileUtilities::getArchiveFileContentsAsString ( string  archivePath,
string  filePath 
)
static

Returns the contents of a file within an archive.

If the file doesn't exist, returns an empty string.

Parameters
archivePathThe archive containing the file.
filePathThe file. The path should be relative to the archive's root.
Returns
The file's contents.
size_t VuoFileUtilities::getAvailableSpaceOnVolumeContainingPath ( string  path)
static

Returns the available space, in bytes, on the volume containing the specified path.

path should be an absolute POSIX path. Its last few path components needn't exist.

Exceptions
std::runtime_error
string VuoFileUtilities::getCachePath ( void  )
static

Returns the filesystem path to the folder that Vuo uses to cache data (without a trailing slash).

unsigned long VuoFileUtilities::getFileLastModifiedInSeconds ( string  path)
static

Returns the time that the file was last modified, in seconds from a reference date.

This is useful for checking which of two files was modified more recently.

size_t VuoFileUtilities::getFirstInsertionIndex ( string  s)
static

Returns the first index at which content can be inserted into a string that was read from a file.

This comes after the Unicode BOM, if present.

string VuoFileUtilities::getSystemModulesPath ( void  )
static

Returns the filesystem path to the system-wide Vuo Modules folder (without a trailing slash).

string VuoFileUtilities::getTmpDir ( void  )
static

Returns the path of the default temporary directory.

string VuoFileUtilities::getUserModulesPath ( void  )
static

Returns the filesystem path to the user-specific Vuo Modules folder (without a trailing slash).

string VuoFileUtilities::getVuoFrameworkPath ( void  )
static

Returns the absolute path of Vuo.framework (without a trailing slash), or an empty string if Vuo.framework cannot be located.

void VuoFileUtilities::makeDir ( string  path)
static

Creates a new directory (and parent directories if needed), if it doesn't already exist.

Exceptions
std::runtime_errorThe directory couldn't be created.
string VuoFileUtilities::makeTmpDir ( string  dir)
static

Creates a new temporary directory, avoiding any name conflicts with existing files.

Returns the path of the directory (without a trailing slash).

string VuoFileUtilities::makeTmpDirOnSameVolumeAsPath ( string  path)
static

Creates a new temporary directory, avoiding any name conflicts with existing files.

The temporary directory will be on the same filesystem as the specified path, to facilitate using rename() (for example). onSameVolumeAsPath needn't already exist.

Returns the path of the directory (without a trailing slash).

string VuoFileUtilities::makeTmpFile ( string  file,
string  extension,
string  directory = "/tmp" 
)
static

Creates a new temporary file, avoiding any name conflicts with existing files.

Creates the file in the specified directory if one is provided, or in "/tmp" otherwise.

Returns the path of the file.

Todo:
Keep file open and return file handle. (https://b33p.net/kosada/node/4987)
void VuoFileUtilities::moveFile ( string  fromPath,
string  toPath 
)
static

Moves the file from fromPath to toPath.

Exceptions
std::runtime_errorThe file couldn't be moved.
void VuoFileUtilities::moveFileToTrash ( string  filePath)
static

Moves the specified file to the user's trash folder.

Exceptions
std::runtime_errorThe file couldn't be moved.
void VuoFileUtilities::preserveOriginalFileName ( string &  fileContents,
string  originalFileName 
)
static

Saves originalFileName into fileContents so that, when fileContents is written to some other file path, originalFileName will still be the name that shows up in compile errors/warnings and in the FILE macro.

This function inserts a preprocessor directive at the beginning of fileContents. Any modifications to fileContents after this function is called should keep the preprocessor directive on the first line.

string VuoFileUtilities::readFileToString ( string  path)
static

Reads the whole contents of the file into a string.

Exceptions
std::runtime_errorThe file couldn't be read.
string VuoFileUtilities::readStdinToString ( void  )
static

Reads from standard input into a string until the end-of-file is reached.

void VuoFileUtilities::splitPath ( string  path,
string &  dir,
string &  file,
string &  extension 
)
static

Splits path into its directory, file name, and file extension.

Parameters
[in]pathThe path to split.
[out]dirThe directory in path, if any. Ends with a file separator (e.g. '/') if there was one in path.
[out]fileThe file name in path, if any.
[out]extensionThe file extension in path, if any. Does not include the '.' character.
See Also
VuoUrl_getFileParts
void VuoFileUtilities::writeRawDataToFile ( const char *  data,
size_t  numBytes,
string  file 
)
static

Writes the array of bytes to the file.

If the file already exists, it gets overwritten.

Exceptions
std::runtime_errorThe file couldn't be written.
void VuoFileUtilities::writeStringToFile ( string  s,
string  file 
)
static

Writes the string to the file.

If the file already exists, it gets overwritten.

Exceptions
std::runtime_errorThe file couldn't be written.

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