Device Monitoring Studio - Monitor, log and analyze data coming through PC ports and connections
Download Device Monitoring Studio 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 {

    // Methods
    ${createFile}(path: string,
        openMode: ${File.OpenMode},
        access: ${File.Access},
        share?: ${File.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;
}
// This interface is not available in managed environment
// This interface is not available in native environment

IFileManager Methods

createFile

createFile(path: string,
    openMode: ${File.OpenMode},
    access: ${File.Access},
    share?: ${File.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 File.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 File.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", File.OpenMode.OpenExisting, File.Access.Read, File.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.