MeVisLab Scripting Reference
MLABFileManager Class Reference

#include <mlabScriptWrappers.h>

Inherits QObject.

Public Slots

FileManager methods


QString readStringFromFile (const QString &filename)
 
bool writeStringToFile (const QString &filename, const QString &string)
 
bool appendStringToFile (const QString &filename, const QString &string)
 
QString readStringFromFileUTF8 (const QString &filename)
 
bool writeStringToFileUTF8 (const QString &filename, const QString &string)
 
bool appendStringToFileUTF8 (const QString &filename, const QString &string)
 
bool mkdir (const QString &path)
 
bool rmdir (const QString &path)
 
bool recursiveRemoveDir (const QString &path)
 
bool remove (const QString &filename)
 
bool moveFileToTrash (const QString &filename)
 
bool rename (const QString &filename, const QString &newfilename)
 
bool copy (const QString &src, const QString &dst)
 
bool exists (const QString &filename)
 
bool isDir (const QString &filename)
 
bool isReadable (const QString &filename)
 
bool isWritable (const QString &filename)
 
QString getTmpDir ()
 
QString getHomeDir ()
 
QString getExecutable (const QString &name)
 
QString getExecutableOnLocalMachine (const QString &name)
 
QString getCommonMeVisAppDataDir ()
 
void setApplicationSupportUmbrellaDirectoryName (const QString &dirName)
 
QString getLocalApplicationSupportDirectory (const QString &appName=QString())
 
QString getUserApplicationSupportDirectory (const QString &appName=QString())
 
QString getLocalApplicationCachesDirectory (const QString &appName=QString())
 
QString getUserApplicationCachesDirectory (const QString &appName=QString())
 
QStringList getDrives ()
 
uint getFileSize (const QString &filename)
 
QDateTime getCreationDate (const QString &filename)
 
QDateTime getLastModifiedDate (const QString &filename)
 
QDateTime getLastReadDate (const QString &filename)
 
QString normalizePath (const QString &filename)
 
QString cleanupPath (const QString &filename)
 
QString nativePath (const QString &filename)
 
QStringList contentOfDirectory (const QString &path)
 
QStringList contentOfDirectory (const QString &path, const QString &filter)
 
QStringList recursiveContentOfDirectory (const QString &path, const QString &filter)
 
QStringList recursiveContentOfDirectory (const QString &path)
 
QMap< QString, QVariant > splitPath (const QString &path)
 
QString abbreviateFilename (const QString &filename, int length)
 
QString absPath (const QString &filename, const QString &currentDir)
 
QString getUniqueFilename (const QString &path, const QString &prefix, const QString &postfix)
 
bool isPathInside (const QString &path, const QString &containerPath)
 
quint64 diskCapacity (const QString &path)
 
quint64 availableDiskSpace (const QString &path)
 

Detailed Description

Global MLABFileManager object available in all scripts.

The MLABFileManager can be used to access the local file system. It can:

  • read content of directories via contentOfDirectory()
  • read/write strings to files (appendStringToFile(), writeStringToFile(), readStringFromFile())
  • read file attributes
  • create/copy/remove/rename directories

Member Function Documentation

◆ abbreviateFilename

QString MLABFileManager::abbreviateFilename ( const QString & filename,
int length )
slot

Abbreviates the filename so that drive and filename are still visible (length is only a hint, the string might be longer because the full filename will be visible).

◆ absPath

QString MLABFileManager::absPath ( const QString & filename,
const QString & currentDir )
slot

Makes the given path absolute if it is relative (by using the currentDir).

◆ appendStringToFile

bool MLABFileManager::appendStringToFile ( const QString & filename,
const QString & string )
slot

Appends string to a file (UTF-8 encoded).

◆ appendStringToFileUTF8

bool MLABFileManager::appendStringToFileUTF8 ( const QString & filename,
const QString & string )
slot

Appends a string to a file (UTF-8 ncoded).

◆ availableDiskSpace

quint64 MLABFileManager::availableDiskSpace ( const QString & path)
slot

Returns the available space of the disk on which the given path exists in bytes.

◆ cleanupPath

QString MLABFileManager::cleanupPath ( const QString & filename)
slot

Normalizes the path to contain "/" forward slashes only and removes "..".

◆ contentOfDirectory [1/2]

QStringList MLABFileManager::contentOfDirectory ( const QString & path)
slot

Returns a string list with content of the given directory.

The method does not search recursively and returns directories and files. The returned strings contain filenames relative to path. NOTE: This does not list hidden nor system files.

◆ contentOfDirectory [2/2]

QStringList MLABFileManager::contentOfDirectory ( const QString & path,
const QString & filter )
slot

Returns a string list with content of the given directory filtered with the given filter.

The method does not search recursively and returns files (not directories) that match the filter. The returned strings contain filenames relative to path. NOTE: This does not list hidden nor system files.

The filter can contain any number of filters separated by " " or ";". Example: "*.cpp *.h" will return cpp and h files

◆ copy

bool MLABFileManager::copy ( const QString & src,
const QString & dst )
slot

Copies a file (not a directory!) (returns true if OK).

◆ diskCapacity

quint64 MLABFileManager::diskCapacity ( const QString & path)
slot

Returns the capacity of the disk on which the given path exists in bytes.

◆ exists

bool MLABFileManager::exists ( const QString & filename)
slot

Returns whether file exists.

◆ getCommonMeVisAppDataDir

QString MLABFileManager::getCommonMeVisAppDataDir ( )
slot

Returns the directory that is common to all MeVis applications for sharing their settings.

◆ getCreationDate

QDateTime MLABFileManager::getCreationDate ( const QString & filename)
slot

Returns the creation date/time of the file.

◆ getDrives

QStringList MLABFileManager::getDrives ( )
slot

Returns a list of available drives on Windows, on Unix just returns "/" (root).

◆ getExecutable

QString MLABFileManager::getExecutable ( const QString & name)
slot

Returns the absolute path of the given executable (where name is given without debug and file extension).

The executable is searched in all MeVisLab packages (in the bin directories). It does NOT try to locate the executable outside of the MeVisLab installation.

◆ getExecutableOnLocalMachine

QString MLABFileManager::getExecutableOnLocalMachine ( const QString & name)
slot

Returns the absolute path to an executable located somewhere on the user's computer: the executable's name is given without any extension.

First, the function tries to locate the executable within MeVisLab and then on the whole system. Each platform may try a different approach to locate the executable.

◆ getFileSize

uint MLABFileManager::getFileSize ( const QString & filename)
slot

Returns the size of the file.

◆ getHomeDir

QString MLABFileManager::getHomeDir ( )
slot

Returns the users home dir.

◆ getLastModifiedDate

QDateTime MLABFileManager::getLastModifiedDate ( const QString & filename)
slot

Returns the last modified date/time of the file.

◆ getLastReadDate

QDateTime MLABFileManager::getLastReadDate ( const QString & filename)
slot

Returns the last read date/time of the file.

◆ getLocalApplicationCachesDirectory

QString MLABFileManager::getLocalApplicationCachesDirectory ( const QString & appName = QString())
slot

Returns the absolute path to the directory in which to store discardable cache files available to everyone on this machine.

If the appName argument is provided, use the caches directory with the given name. Otherwise the caches directory of the current, calling application is returned.

◆ getLocalApplicationSupportDirectory

QString MLABFileManager::getLocalApplicationSupportDirectory ( const QString & appName = QString())
slot

Returns the absolute path to the directory in which to store application support data available to everyone on this machine.

If the appName argument is provided, use the application support directory with the given name. Otherwise the application support directory of the current, calling application is returned (This should be the same value as returned by getCommonMeVisAppDataDir() ).

◆ getTmpDir

QString MLABFileManager::getTmpDir ( )
slot

Returns the path to the temporary directory (uses TEMP or TMP environment vars, falls back to /tmp on Linux.

◆ getUniqueFilename

QString MLABFileManager::getUniqueFilename ( const QString & path,
const QString & prefix,
const QString & postfix )
slot

Creates a unique filename of the form path + prefix + uniqueNumber + postfix, which is guaranteed to be non existent.

Unique numbers start from 0 until a non existent file is found. If the path does not exist, an empty string is returned.

Global MLABFileManager object available in all scripts.
Definition mlabScriptWrappers.h:244
QString getTmpDir()
Returns the path to the temporary directory (uses TEMP or TMP environment vars, falls back to /tmp on...
QString getUniqueFilename(const QString &path, const QString &prefix, const QString &postfix)
Creates a unique filename of the form path + prefix + uniqueNumber + postfix, which is guaranteed to ...

◆ getUserApplicationCachesDirectory

QString MLABFileManager::getUserApplicationCachesDirectory ( const QString & appName = QString())
slot

Returns the absolute path to the directory in which to store discardable cache files available to the current user.

If the appName argument is provided, use the caches directory with the given name. Otherwise the caches directory of the current, calling application is returned.

◆ getUserApplicationSupportDirectory

QString MLABFileManager::getUserApplicationSupportDirectory ( const QString & appName = QString())
slot

Returns the absolute path to the directory in which to store application support data available to the current user.

If the appName argument is provided, use the application support directory with the given name. Otherwise the application support directory of the current, calling application is returned.

◆ isDir

bool MLABFileManager::isDir ( const QString & filename)
slot

Returns whether file is a directory.

◆ isPathInside

bool MLABFileManager::isPathInside ( const QString & path,
const QString & containerPath )
slot

Returns whether path is contained inside containerPath.

The check is performed with and without resolving symbolic links.

◆ isReadable

bool MLABFileManager::isReadable ( const QString & filename)
slot

Returns whether file is readable.

◆ isWritable

bool MLABFileManager::isWritable ( const QString & filename)
slot

Returns whether file is writable.

◆ mkdir

bool MLABFileManager::mkdir ( const QString & path)
slot

Creates a deep directory (returns true if OK).

◆ moveFileToTrash

bool MLABFileManager::moveFileToTrash ( const QString & filename)
slot

File is moved to the trash folder on supported systems, otherwise the file is removed (returns true if OK).

This function is useful in all cases where the file represents a user document or a file that may be open and still required by the system, e.g. a dynamic library.

◆ nativePath

QString MLABFileManager::nativePath ( const QString & filename)
slot

Converts slashes to system default "\" on Windows, "/" on Linux.

◆ normalizePath

QString MLABFileManager::normalizePath ( const QString & filename)
slot

Normalizes the path to contain "/" forward slashes only.

◆ readStringFromFile

QString MLABFileManager::readStringFromFile ( const QString & filename)
slot

Returns file const as a string (assumes UTF-8 encoding, falls back to Latin1 in case of decoding errors) .

Return value is empty when read fails.

◆ readStringFromFileUTF8

QString MLABFileManager::readStringFromFileUTF8 ( const QString & filename)
slot

Returns file content as a string (uses UTF-8 encoding, faulty characters removed/replaced).

Return value is empty when read fails.

◆ recursiveContentOfDirectory [1/2]

QStringList MLABFileManager::recursiveContentOfDirectory ( const QString & path)
slot

Returns a string list with recursive content of the given directory.

The method searches recursively and returns directories and files. NOTE: This does not list hidden nor system files. The returned strings contain filenames relative to path.

◆ recursiveContentOfDirectory [2/2]

QStringList MLABFileManager::recursiveContentOfDirectory ( const QString & path,
const QString & filter )
slot

Returns a string list with recursive content of the given directory.

The method searches recursively and returns files (not directories) that match the filter. The returned strings contain filenames relative to path. NOTE: This does not list hidden nor system files.

The filter can contain any number of filters separated by " " or ";". Example: "*.cpp *.h" will return cpp and h files

◆ recursiveRemoveDir

bool MLABFileManager::recursiveRemoveDir ( const QString & path)
slot

Removes a directory and all its content recursively (returns true if OK).

◆ remove

bool MLABFileManager::remove ( const QString & filename)
slot

Removes a given file (returns true if OK).

◆ rename

bool MLABFileManager::rename ( const QString & filename,
const QString & newfilename )
slot

Renames a given file (returns true if OK).

◆ rmdir

bool MLABFileManager::rmdir ( const QString & path)
slot

Removes a directory (returns true if ok, directory must be empty).

◆ setApplicationSupportUmbrellaDirectoryName

void MLABFileManager::setApplicationSupportUmbrellaDirectoryName ( const QString & dirName)
slot

Set the name of a folder that contains the support data directories of all MeVisLab applications. No such folder is created/used if empty.

Default: 'MeVis'.

◆ splitPath

QMap< QString, QVariant > MLABFileManager::splitPath ( const QString & path)
slot

Obtains the directory, filename, basename, and extension portions of path.

The returned object has the properties

  • dir: The directory part
  • name: The filename part
  • base: The basename part
  • ext: The extension part (the part from last . to end of path) These strings fulfill the relation path = dir+name = dir+base+ext

◆ writeStringToFile

bool MLABFileManager::writeStringToFile ( const QString & filename,
const QString & string )
slot

Writes a string to a file (UTF-8 encoded).

◆ writeStringToFileUTF8

bool MLABFileManager::writeStringToFileUTF8 ( const QString & filename,
const QString & string )
slot

Writes a string to a file (UTF-8 encoded).