ProtoTwin API
    Preparing search index...

    Class File

    Virtual file. Represents a file in the virtual filesystem and provides various filesystem related convenience functions.

    Index

    Constructors

    • Constructor.

      Parameters

      • path: string

        The file path.

      Returns File

    Properties

    path: string

    The file path.

    Accessors

    • get exists(): boolean

      Whether the file currently exists.

      Returns boolean

    Methods

    • Writes the specified binary data to the file.

      Parameters

      • data: Uint8Array

        The binary data.

      Returns void

      Error Exception is thrown if the file could not be written.

    • Combines two paths.

      Parameters

      • lhs: string

        The first path.

      • rhs: string

        The second path.

      Returns string

      The combined path.

    • Copies a file from the specified source path to the specified destination path.

      Parameters

      • sourcePath: string

        The source file path.

      • destinationPath: string

        The destination file path.

      Returns void

    • Creates an empty file at the specified path.

      Parameters

      • path: string

        The file path.

      Returns void

    • Deletes the file at the specified path if it exists.

      Parameters

      • path: string

        The file path.

      Returns void

    • Extracts the directory path from the specified file path.

      Parameters

      • path: string

        The file path.

      Returns string

      The directory path.

      The trailing forward slash is not included in the returned directory path.

    • Whether a file or directory exists at the specified path.

      Parameters

      • path: string

        The path.

      Returns boolean

      True if the file or directory exists, false otherwise.

    • Extracts the file extension from the specified file path.

      Parameters

      • path: string

        The file path.

      Returns string

      The file extension.

      The period is not included in the returned file extension.

    • Extracts the file name from the specified file path.

      Parameters

      • path: string

        The file path.

      • includeExtension: boolean = true

        Whether to include the extension in the file name.

      Returns string

      The file name.

    • Whether a directory exists at the specified path.

      Parameters

      • path: string

        The path.

      Returns boolean

      True if a directory exists, false otherwise.

    • Lists the contents of a directory.

      Parameters

      • path: string

        The directory path.

      • includePath: boolean = false

        Whether to include the directory path in the returned list of file names/paths.

      Returns null | string[]

      The list of file and subdirectory names/paths.

      This function does not recurse into any subdirectories, but it does include any subdirectories in the returned list.

    • Lists the contents of a directory and any subdirectories.

      Parameters

      • path: string

        The directory path.

      Returns null | string[]

      The list of file paths.

      This function recurses into subdirectories and does not include directories in the returned list.

    • Prompts the user to open a file.

      Parameters

      • description: undefined | string = undefined

        The (optional) file type description.

      • mimetypes: undefined | string[] = undefined

        The (optional) array of supported mimetypes.

      • extensions: undefined | string[] = undefined

        The (optional) array of supported file extensions.

      Returns Promise<ArrayBuffer>

      The loaded data.

    • Reads the binary data from the file.

      Parameters

      • path: string

        The file path.

      Returns Uint8Array

      The binary data.

      Error Exception is thrown if the file does not exist or could not be opened for reading.

    • Moves the file at the the specified source path to the specified destination path.

      Parameters

      • sourcePath: string

        The source file path.

      • destinationPath: string

        The destination file path.

      Returns void

    • Prompts the user to save the specified binary data a file.

      Parameters

      • data: ArrayBuffer

        The binary data.

      • filename: undefined | string = undefined

        The (optional) default filename.

      • extensions: undefined | string[] = undefined

        The (optional) array of file extensions.

      Returns Promise<void>

    • Writes the specified binary data to a file.

      Parameters

      • path: string

        The file path.

      • data: Uint8Array

        The binary data.

      Returns void

      Error Exception is thrown if the file could not be written.