Programming Reference for VirtualLab Fusion  2026.1
Loading...
Searching...
No Matches
FileSystemSupport Class Reference

This class is subject to change. Programs using this class may require changes with a new version of VirtualLab.
Static class to support access to the file system and handling of file names. More...

Static Public Member Functions

static string AddExtension (string fileName, string extension)
 Adds an extension to the given file name.
 
static void CopyDirectory (string sourceDir, string destinationDir, bool recursive, bool overwrite)
 Copies all files from the given source directory to the destination directory.
 
static string CreateTemporaryFileName (string path, string extension)
 Creates a unique random file name with the given path and extension.
 
static string CreateTemporarySubDirectory ()
 Creates a new sub-directory in the version specific ApplicationSpecificTemporaryDirectory.
 
static void DeleteFileIfEmpty (string? filePath)
 Deletes the given file if it is empty (i.e. has a length of zero bytes).
 
static void DeleteTempDir ()
 Deletes the main temp dir.
 
static void EnsureThatDirectoryExists (string path, bool containsFileName=false)
 Ensures that the given directory exists.
 
static string[] GetFilesFromDirectory (string directory, string searchPattern="*", bool excludeBackupFiles=false, bool includeSubDirectories=true)
 Wrapper around the Directory.GetFiles method with the following changes:
• It is optionally searched recursively in all sub-directories.

• Inaccessible files are ignored (.Net 8 only).
• You can optionally exclude backup files created by the MoveToBackupFile(string, string) method.
 
static string GetSpecialFolder (Environment.SpecialFolder specialFolder, bool createVersionSpecificSubfolder)
 Gets the specified special folder to which company and product name have been added as subdirectories. For example "c:\Users\{user}\AppData\Roaming\Wyrowski Photonics GmbH\VirtualLab Fusion\" is returned for "Environment.SpecialFolder.ApplicationData".
 
static bool IsDirectoryEmpty (string path)
 Checks whether the given directory is empty.
 
static void MoveToBackupFile (string fileName, string description="")
 Moves a (faulty) file to a backup file, whereas already existing backup files are not overwritten.
 
static void RecursiveDelete (DirectoryInfo directoryToDelete)
 Deletes the given directory and all its sub-directories. If there are files in the directory which have the read-only attribute or cannot be deleted because they are still in use or due to lacking access rights, the normal Directory.Delete just throws an exception and many files are not deleted.
 

Properties

static string ApplicationSpecificTemporaryDirectory [get]
 Gets the application and version specific temporary directory as sub-directory of TemporaryDirectory.
 
static string ClipboardDirectory [get]
 Temporary folder where files are stored which are passed around like with the Windows™ Clipboard.
 
static string ExecutableDirectory [get]
 Gets the directory where the main executable of the application is located.
 
static string ProgramDataDirectoryCurrentVersion [get]
 Gets and sets the directory where data from LightTrans or Wyrowski Photonics is stored for the current user. For example catalogs, detector add-ons, …. Every user has its own program data directory because "standard users" (without administrator privileges) cannot update into the normal program data directory.
 
static string TemporaryDirectory [get, set]
 Temporary directory to save temporary data during calculations.
 
static string UserDataDirectory [get, set]
 

Detailed Description

This class is subject to change. Programs using this class may require changes with a new version of VirtualLab.
Static class to support access to the file system and handling of file names.

Member Function Documentation

◆ AddExtension()

static string AddExtension ( string fileName,
string extension )
static

Adds an extension to the given file name.

Parameters
fileNameThe file name.
extensionThe extension.
Returns
The file name with the added extension. If the extension does not contain a leading period (.), a period is added. In contrast to Path.ChangeExtension, "filename.3" + ".ext" becomes "filename.3.ext", not "filename.ext". If the file name already ends with the given extension, it is not added anew.

◆ CopyDirectory()

static void CopyDirectory ( string sourceDir,
string destinationDir,
bool recursive,
bool overwrite )
static

Copies all files from the given source directory to the destination directory.

Parameters
sourceDirThe source directory.
destinationDirThe destination directory.
recursiveIf set to true, also the content of all sub-directories is copied.
overwriteIf set to true existing files are overwritten, even if they are read-only.
Exceptions
DirectoryNotFoundExceptionSource directory not found.

◆ CreateTemporaryFileName()

static string CreateTemporaryFileName ( string path,
string extension )
static

Creates a unique random file name with the given path and extension.

Parameters
pathPath in which uniqueness with the file name is ensured.
extensionThe file extension (e.g. ".mtr") appended to the file name.
Returns
The random file name including the given path and the extension.

◆ CreateTemporarySubDirectory()

static string CreateTemporarySubDirectory ( )
static

Creates a new sub-directory in the version specific ApplicationSpecificTemporaryDirectory.

Returns
Full path of the newly created sub-directory for temporary files.

◆ DeleteFileIfEmpty()

static void DeleteFileIfEmpty ( string? filePath)
static

Deletes the given file if it is empty (i.e. has a length of zero bytes).

Parameters
filePathThe complete path of the file.

◆ EnsureThatDirectoryExists()

static void EnsureThatDirectoryExists ( string path,
bool containsFileName = false )
static

Ensures that the given directory exists.

Parameters
pathThe path to check.
containsFileNameIf this optional parameter is set to true it is assumed that the path contains a file name (which is removed prior to the check.

◆ GetFilesFromDirectory()

static string[] GetFilesFromDirectory ( string directory,
string searchPattern = "*",
bool excludeBackupFiles = false,
bool includeSubDirectories = true )
static

Wrapper around the Directory.GetFiles method with the following changes:
• It is optionally searched recursively in all sub-directories.

• Inaccessible files are ignored (.Net 8 only).
• You can optionally exclude backup files created by the MoveToBackupFile(string, string) method.

Parameters
directoryThe relative or absolute path to the directory to search. This string is not case-sensitive.
searchPatternOptional search pattern. Only file names containing this pattern are included in the result.
excludeBackupFilesIf this optional parameter is set to true backup files created by the MoveToBackupFile(string, string) or the GetBinaryBackupFileName(string) method are excluded.
includeSubDirectoriesIf this optional parameter is set to false, only the given directory is searched. Else also all sub-directories are searched.
Returns
An array of the full names (including paths) of the found files in the specified directory, or an empty array if no files are found or if the directory does not exist.

◆ GetSpecialFolder()

static string GetSpecialFolder ( Environment.SpecialFolder specialFolder,
bool createVersionSpecificSubfolder )
static

Gets the specified special folder to which company and product name have been added as subdirectories. For example "c:\Users\{user}\AppData\Roaming\Wyrowski Photonics GmbH\VirtualLab Fusion\" is returned for "Environment.SpecialFolder.ApplicationData".

Parameters
specialFolderEnumeration entry specifying the special folder.
createVersionSpecificSubfolderIf set to true a version specific sub-folder is created (e.g. "2024.1").
Returns
The complete directory path, with company, product name, and optionally version as sub-directories. If anything fails, the temporary path is returned.

◆ IsDirectoryEmpty()

static bool IsDirectoryEmpty ( string path)
static

Checks whether the given directory is empty.

Parameters
pathThe path to the directory.
Returns
True if the specified directory is empty.

◆ MoveToBackupFile()

static void MoveToBackupFile ( string fileName,
string description = "" )
static

Moves a (faulty) file to a backup file, whereas already existing backup files are not overwritten.

Parameters
fileNameName of the file.
descriptionThe description for the error message. Must end with a period. E.g. "File could not be read." If this optional parameter is not specified, no error message is put out.

◆ RecursiveDelete()

static void RecursiveDelete ( DirectoryInfo directoryToDelete)
static

Deletes the given directory and all its sub-directories. If there are files in the directory which have the read-only attribute or cannot be deleted because they are still in use or due to lacking access rights, the normal Directory.Delete just throws an exception and many files are not deleted.

Parameters
directoryToDeleteThe directory to delete.

Property Documentation

◆ UserDataDirectory

string UserDataDirectory
staticgetset
 Directory containing all user-defined catalogs and log files.

 </summary>