Virtual Serial Port Tools - Advanced serial port configurations for your custom ports usage scenario
Download Virtual Serial Port Tools Hide this button

IFileManager Interface

This interface is implemented by File Manager object. It provides basic methods to work with a file system, like opening or creating files and folders, deleting files and folders and enumerating the contents of a folder.

Declaration

interface IFileManager {
    // Properties
    ${tempFolder}: string;
    ${windowsFolder}: string;
    ${systemFolder}: string;
    ${programDataFolder}: string;

    // Methods
    ${createFile}(path: string,
        openMode: ${FS.OpenMode},
        access: ${FS.Access},
        share?: ${FS.Share}): ${IFile};
    ${deleteFile}(path: string): void;
    ${enumFiles}(folder: string, mask?: string): Promise<string[]>;
    ${copyFile}(source: string, destination: string, overwrite?: boolean): Promise<void>;
    ${moveFile}(source: string, destination: string, overwrite?: boolean): Promise<void>;
    ${createFolder}(path: string): void;
    ${deleteFolder}(path: string): void;
    ${loadTextFile}(path: string, utf8?: boolean): string;
}
// This interface is not available in managed environment
// This interface is not available in native environment

IFileManager Properties

tempFolder

tempFolder: string;
// This property is not available in managed environment
// This property is not available in native environment

Get the system temporary folder. Usually equals to c:\Windows\TEMP.

windowsFolder

windowsFolder: string;
// This property is not available in managed environment
// This property is not available in native environment

Get the OS root folder. Usually equals to c:\Windows.

systemFolder

systemFolder: string;
// This property is not available in managed environment
// This property is not available in native environment

Get the OS system folder. Usually equals to c:\Windows\System32.

programDataFolder

programDataFolder: string;
// This property is not available in managed environment
// This property is not available in native environment

Get the ProgramData folder. Usually equals to c:\ProgramData.

IFileManager Methods

createFile

createFile(path: string,
    openMode: ${FS.OpenMode},
    access: ${FS.Access},
    share?: ${FS.Share}): ${IFile};
// This method is not available in managed environment
// This method is not available in native environment
path
Full path to the file being opened or created.
openMode
File opening mode. See FS.OpenMode topic for more information.
access
File access mode. A file may be opened for reading, writing or both reading and writing.
share
File sharing mode. Tells the file system how it should handle other process attempts to open a file. If omitted, equals to FS.Share.Exclusive.

An opened file object.

Creates or opens a file.

Open an existing file for reading

var file = fileManager.createFile("c:\\temp\\file.txt", FS.OpenMode.OpenExisting, FS.Access.Read, FS.Share.Read);

deleteFile

deleteFile(path: string): void;
// This method is not available in managed environment
// This method is not available in native environment
path
Full path to the file to delete.

Deletes a given file.

enumFiles

enumFiles(folder: string, mask?: string): Promise<string[]>;
// This method is not available in managed environment
// This method is not available in native environment
folder
Full path to the folder the caller wants to enumerate.
mask
An optional mask to match files during enumeration. If omitted, equals to "*".

Enumerate files in a given folder. The method executes asynchronously and returns a list of file names that match a given mask.

Enumerating files in a folder

var files = await fileManager.enumFiles("c:\\temp", "*.txt");

copyFile

copyFile(source: string, destination: string, overwrite?: boolean): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
source
Full path to the source file.
destination
Full path to the destination file.
overwrite
An optional parameter that tells if the destination file should be overridden if it exists. If omitted, defaults to false.

Copies a source file to destination. The method executes asynchronously.

Copying a file

await fileManager.copyFile(source, destination);

moveFile

moveFile(source: string, destination: string, overwrite?: boolean): Promise<void>;
// This method is not available in managed environment
// This method is not available in native environment
source
Full path to the source file.
destination
Full path to the destination file.
overwrite
An optional parameter that tells if the destination file should be overridden if it exists. If omitted, defaults to false.

Moves a source file to destination or renames a file. The method executes asynchronously.

Renaming a file

await fileManager.moveFile(source, destination);

createFolder

createFolder(path: string): void;
// This method is not available in managed environment
// This method is not available in native environment
path
Full path to the folder being created.

Creates a folder. If one or more intermediate folders in a given path do not exist, they are also created by this function.

deleteFolder

deleteFolder(path: string): void;
// This method is not available in managed environment
// This method is not available in native environment
path
Full path to the folder being deleted.

Deletes a given folder. A folder must be empty to be successfully deleted.

loadTextFile

loadTextFile(path: string, utf8?: boolean): string;
// This method is not available in managed environment
// This method is not available in native environment
path
Full path to a file.
utf8
Optional flag to force the file to be treated as UTF8-encoded. Defaults to true if omitted.

This method attempts to load and parse a text file. It tries to automatically determine the text file encoding by analyzing its structure and presence of BOM at the beginning of a file.