Class FileSystem

The FileSystem class provides static methods for the manipulation of files and filepaths.

Constructors

Properties

kAltDirectorySeparatorChar: FilePath

Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.

kDirectorySeparatorChar: FilePath

Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.

kPosixDirectorySeparatorChar: FilePath

Provides a character used to separate directory levels in a path string that reflects a hierarchical file system organization on POSIX systems.

kWindowsDirectorySeparatorChar: FilePath

Provides a character used to separate directory levels in a path string that reflects a hierarchical file system organization on Windows systems.

packageFileExtension = ".rpak"

The file extension for the RSX package format. The string includes the dot filename separate.

Methods

  • Changes the extension of a path string.

    Type Parameters

    Parameters

    • path: T

      The path information to modify. The path cannot contain any of the characters defined in System.IO.Path.GetInvalidPathChars.

    • extension: string

      The new extension (with or without a leading period). Specify null to remove an existing extension from path.

    Returns T

    The modified path information.On Windows-based desktop platforms, if path is null or an empty string (""), the path information is returned unmodified.

  • Combines two strings into a path.

    Type Parameters

    Parameters

    • path1: T

      The first path to combine.

    • path2: string | T

      The second path to combine.

    Returns T

    The combined paths.

  • Checks if two paths are equal.

    Type Parameters

    Parameters

    • a: T

      First path.

    • b: T

      Second path.

    Returns boolean

    True if both paths point to the same place.

  • Recursively copies a directory from one path to another, while creating any parent directories if they don't already exist.

    Parameters

    • source: FilePath

      Path to the directory to copy.

    • destination: FilePath

      Path determining where the directory copy will be placed.

    Returns void

  • Copies an existing file to a new file. Overwriting a file of the same name is not allowed.

    Parameters

    • sourceFileName: FilePath

      The file to copy.

    • destFileName: FilePath

      The name of the destination file. This cannot be a directory or an existing file.

    Returns void

  • Copies a file from one path to another, while creating any parent directories if they don't already exist.

    Parameters

    • source: FilePath

      Path to the file to copy.

    • destination: FilePath

      Path to the copied file.

    Returns void

  • Creates all directories and subdirectories in the specified path unless they already exist.

    Parameters

    Returns boolean

    True upon success.

  • Deletes the specified directory and, if indicated, any subdirectories and files in the directory.

    Parameters

    • path: FilePath

      The name of the directory to remove.

    • recursive: boolean

      true to remove directories, subdirectories, and files in path; otherwise, false.

    Returns void

  • Deletes the specified file.

    Parameters

    • path: FilePath

      The name of the file to be deleted. Wildcard characters are not supported.

    Returns void

  • Ensures that the given path directory separators are consistent to the current platform.

    Type Parameters

    Parameters

    • path: T

    Returns T

  • Creates a folder at the specified path if it does not exist yet.

    Parameters

    • fullPath: FilePath

      Full path to a full folder to create.

    Returns boolean

    True if the directory exists or was created, false if the directory couldn't be created

  • Ensures that the given path starts with the given prefix. Same path if already does.

    Type Parameters

    Parameters

    • path: T

      The path to check the suffix for.

    • prefix: string | T

      The prefix to add to the path if not yet present.

    Returns T

    The given path prefixed with the given prefix. The same path if already contains the given suffix.

  • Ensures that the given path ends with the given suffix. Same path if already does.

    Type Parameters

    Parameters

    • path: T

      The path to check the suffix for.

    • suffix: string | T

      The suffix to add to the path if not yet present.

    Returns T

    The given path suffixed with the given suffix. The same path if already contains the given suffix.

  • Gets the current working directory of the application.

    Returns FilePath

    A string that contains the path of the current working directory, and does not end with a backslash ().

  • Returns an array of directory names in a specified path.

    Parameters

    • filePath: FilePath

      The relative or absolute path to the directory to search. This string is not case-sensitive.

    • recursive: boolean

    Returns FilePath[]

    An array of the full names (including paths) for the directories in the directory specified by path.

  • Returns the extension of the specified path string.

    Parameters

    • path: string | FilePath

      The path string from which to obtain the file name and extension.

    Returns string

    The extension of the specified path (including the period "."), or null, or System.String.Empty.

  • Returns the file name and extension of the specified path string.

    Type Parameters

    Parameters

    • path: T

      The path of the file.

    Returns T

    The characters after the last directory character in path.

  • Returns the file name of the specified path string without the extension.

    Type Parameters

    Parameters

    • path: T

      The path of the file.

    Returns T

    The string returned by System.IO.Path.GetFileName(System.String), minus the last period (.) and all characters following it.

  • Returns an array of file names in a specified path.

    Parameters

    • filePath: string | FilePath

      The relative or absolute path to the directory to search. This string is not case-sensitive.

    • recursive: boolean

    Returns FilePath[]

    An array of the full names (including paths) for the files in the directory specified by path.

  • Gets the size of the file at the specified filePath.

    Parameters

    • filePath: FilePath

      The file to write to.

    Returns number

    The file size.

  • Returns the date and time the specified file or directory was last written to.

    Parameters

    • filepath: FilePath

      The file or directory for which to obtain write date and time information.

    Returns Date

    A Date object set to the date and time that the specified file or directory was last written to. This value is expressed in local time.

  • Returns the parent of the provided path.

    Type Parameters

    Parameters

    • path: T

      Path to return the parent of.

    Returns T

    Parent of the path. This usually means the folder containing the file or folder in the current path.

  • Removes the filename component from the path string.

    Type Parameters

    Parameters

    • path: T

      The path of a file or directory.

    Returns T

    Path without the filename component.

  • Returns the last entry in the path, regardless if that is a directory or a filename.

    Type Parameters

    Parameters

    • path: T

      Path to get the tail of.

    Returns string

    Tail of the path. This might be a directory or a filename.

  • Similar to getTail, but when the given path is a path to a directory, the returned value also contains a separator char at the end to indicate that.

    Type Parameters

    Parameters

    • path: T

      Path to get the tail of.

    Returns T

    Tail of the path. This might be a directory or a filename.

  • Returns whether or not the given path is pointing to a directory.

    Type Parameters

    Parameters

    • path: T

      The path to check for.

    Returns boolean

    True for directory and false for files/resources.

  • Determines whether the given path refers to an existing directory on disk.

    Parameters

    • path: string | FilePath

      The path to test.

    Returns boolean

    true if path refers to an existing directory; false if the directory does not exist or an error occurs

  • Determines whether the specified file exists.

    Parameters

    • path: string | FilePath

      The file to check.

    Returns boolean

    true if the caller has the required permissions and path contains the name of an existing file; otherwise, false.

  • Returns whether or not the given path represents a file or a Resource.

    Type Parameters

    Parameters

    • path: T

      The path to check for.

    Returns boolean

    True for files and resources. False for a directory.

  • Checks if one path is part of an another path.

    Type Parameters

    Parameters

    • path: T

      Path to check if it's part of parent.

    • parent: T

      Parent that might contain path.

    Returns boolean

    True if parent contains path.

  • Gets a value indicating whether the specified path string contains a root.

    Type Parameters

    Parameters

    • path: T

      The path to test.

    Returns boolean

    true if path contains a root; otherwise, false.

  • Determines if the file has the read-only flag set.

    Parameters

    Returns boolean

  • Checks if the provided name can be used as a file name.

    Type Parameters

    Parameters

    • name: T

      Name to check.

    Returns boolean

    True if the name can be used as a file name.

  • Moves a directory from one path to another, while creating any parent directories if they don't already exist.

    Parameters

    • source: FilePath

      Path to the directory to move.

    • destination: FilePath

      New location and/or name of the directory.

    Returns void

  • Moves a file from one path to another, while creating any parent directories if they don't already exist.

    Parameters

    • source: FilePath

      Path to the file to move.

    • destination: FilePath

      New location and/or name of the file.

    Returns void

  • Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

    Parameters

    • path: FilePath

      The file to open for reading.

    Returns number[]

    A byte array containing the contents of the file.

  • Opens a text file, reads all lines of the file, and then closes the file.

    Parameters

    • path: FilePath

      The file to open for reading.

    Returns string

    A string containing all lines of the file.

  • Sets the read-only state of the file.

    Parameters

    • path: FilePath
    • isReadOnly: boolean
    • OptionalisRecursive: boolean

    Returns boolean

  • Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.

    Parameters

    • path: FilePath

      The file to write to.

    • bytes: number[]

    Returns void

    The bytes to write to the file.

  • Creates a new file, writes the specified stream to the file, and then closes the file. If the target file already exists, it is overwritten.

    Parameters

    • filePath: FilePath

      The file to write to.

    • stream: DataStream

      The stream to write to the file.

    • OptionalseekToBeginning: boolean

      If true, seeks the stream to be beginning.

    Returns boolean

  • Creates a new file, asynchronously writes the specified stream to the file, and then closes the file. If the target file already exists, it is overwritten.

    Parameters

    • filePath: FilePath

      The file to write to.

    • stream: DataStream

      The stream to write to the file.

    • OptionalseekToBeginning: boolean

      If true, seeks the stream to be beginning.

    Returns UncertainAsyncOp<boolean, string>

  • Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.

    Parameters

    • filePath: FilePath

      The file to write to.

    • contents: string

      The string to write to the file.

    Returns boolean