FileSystem

A thread safe singleton to access file system apis.

Examples

val documentsDirectory = FileSystem.contentsDirectory

val isFileCreated = FileSystem.touch(documentsDirectory.absolutePath?.byAppending("test.txt")!!)

object FileSystem
object FileSystem
object FileSystem

Functions

appendFile
Link copied to clipboard

Appends contents to the file located at pathComponent. If create is true, then file is created if it does not exist. For binary files, use encoding = ContentEncoding.Base64. The original contents are left unchanged.

If the encoding = ContentEncoding.Base64, then existing contents are first read decoded into a UTF-8 string. The new contents are appended and a new Base64 representation of the concatenated string is written to the file.

Returns true if operation is successful, otherwise false.

common
fun appendFile(pathComponent: PathComponent, contents: String, create: Boolean, encoding: ContentEncoding): Boolean
fun appendFile(pathComponent: PathComponent, contents: String, create: Boolean, encoding: ContentEncoding): Boolean
fun appendFile(path: String, contents: String, create: Boolean, encoding: ContentEncoding): Boolean
fun appendFile(pathComponent: PathComponent, contents: String, create: Boolean, encoding: ContentEncoding): Boolean
fun appendFile(path: String, contents: String, create: Boolean, encoding: ContentEncoding): Boolean

Appends contents to the file located at pathComponent. If create is true, then file is created if it does not exist. For binary files, use encoding = ContentEncoding.Base64. The original contents are left unchanged.

If the encoding = ContentEncoding.Base64, then existing contents are first read decoded into a UTF-8 string. The new contents are appended and a new Base64 representation of the concatenated string is written to the file.

Returns true if operation is successful, otherwise false.

js
fun appendFile(pathComponent: PathComponent, contents: String, create: Boolean, encoding: ContentEncoding): Boolean

Appends contents to the file located at path. If create is true, then file is created if it does not exist. For binary files, use encoding = ContentEncoding.Base64. The original contents are left unchanged.

If the encoding = ContentEncoding.Base64, then existing contents are first read decoded into a UTF-8 string. The new contents are appended and a new Base64 representation of the concatenated string is written to the file.

Returns true if operation is successful, otherwise false.

common
fun appendFile(path: String, contents: String, create: Boolean, encoding: ContentEncoding): Boolean

Appends contents to the file located at path. If create is true, then file is created if it does not exist. For binary files, use encoding = ContentEncoding.Base64. The original contents are left unchanged.

If the encoding = ContentEncoding.Base64, then existing contents are first read decoded into a UTF-8 string. The new contents are appended and a new Base64 representation of the concatenated string is written to the file.

Returns true if operation is successful, otherwise false.

js
fun appendFile(path: String, contents: String, create: Boolean, encoding: ContentEncoding): Boolean
copyFile
Link copied to clipboard

Copies the file from srcPathComponent to destPathComponent. If srcPathComponent is a directory, its contents including hidden files are copied. Returns true if the copy is successful, otherwise false.

common
fun copyFile(srcPathComponent: PathComponent, destPathComponent: PathComponent): Boolean
fun copyFile(srcPathComponent: PathComponent, destPathComponent: PathComponent): Boolean
fun copyFile(srcPath: String, destPath: String): Boolean
fun copyFile(srcPathComponent: PathComponent, destPathComponent: PathComponent): Boolean
fun copyFile(srcPath: String, destPath: String): Boolean

Copies the file from srcPath to destPath. If srcPath is a directory, its contents including hidden files are copied. Returns true if the copy is successful, otherwise false.

common
fun copyFile(srcPath: String, destPath: String): Boolean
equals
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
open operator override fun equals(other: Any?): Boolean
exists
Link copied to clipboard

Returns true if the file or directory exists at pathComponent.

common
fun exists(pathComponent: PathComponent): Boolean
fun exists(pathComponent: PathComponent): Boolean
fun exists(path: String): Boolean
fun exists(pathComponent: PathComponent): Boolean
fun exists(path: String): Boolean

Returns true if the file or directory exists at path.

common
fun exists(path: String): Boolean
hashCode
Link copied to clipboard
open override fun hashCode(): Int
open override fun hashCode(): Int
mkdir
Link copied to clipboard

Creates a directory on pathComponent. If recursive is true, then intermediate directories are also created. Returns true if directory is created successfully.

common
fun mkdir(pathComponent: PathComponent, recursive: Boolean): Boolean
fun mkdir(pathComponent: PathComponent, recursive: Boolean): Boolean
fun mkdir(path: String, recursive: Boolean): Boolean
fun mkdir(pathComponent: PathComponent, recursive: Boolean): Boolean
fun mkdir(path: String, recursive: Boolean): Boolean

Creates a directory on path. If recursive is true, then intermediate directories are also created. Returns true if directory is created successfully.

common
fun mkdir(path: String, recursive: Boolean): Boolean
moveFile
Link copied to clipboard

Moves the file from srcPathComponent to destPathComponent. If srcPathComponent is a directory, its contents including hidden files are moved. Returns true if the move is successful, otherwise false.

common
fun moveFile(srcPathComponent: PathComponent, destPathComponent: PathComponent): Boolean
fun moveFile(srcPathComponent: PathComponent, destPathComponent: PathComponent): Boolean
fun moveFile(srcPath: String, destPath: String): Boolean
fun moveFile(srcPathComponent: PathComponent, destPathComponent: PathComponent): Boolean
fun moveFile(srcPath: String, destPath: String): Boolean

Moves the file from srcPath to destPath. If srcPath is a directory, its contents including hidden files are moved. Returns true if the move is successful, otherwise false.

common
fun moveFile(srcPath: String, destPath: String): Boolean
readDir
Link copied to clipboard

Returns a list of stats for the contents of directory at pathComponent.

fun readDir(pathComponent: PathComponent): List<StatResult>?
fun readDir(pathComponent: PathComponent): List<StatResult>?
fun readDir(pathComponent: PathComponent): List<StatResult>?
fun readDir(path: String): List<StatResult>?
fun readDir(pathComponent: PathComponent): List<StatResult>?
fun readDir(path: String): List<StatResult>?

Returns a list of stats for the contents of directory at path.

fun readDir(path: String): List<StatResult>?
fun readDir(path: String): List<StatResult>?
readFile
Link copied to clipboard

Returns the contents of the file located at pathComponent as ByteArray.

common
fun readFile(pathComponent: PathComponent): ByteArray?
fun readFile(pathComponent: PathComponent): ByteArray?
fun readFile(path: String): ByteArray?
fun readFile(pathComponent: PathComponent, encoding: ContentEncoding): String?
fun readFile(path: String, encoding: ContentEncoding): String?
fun readFile(pathComponent: PathComponent): ByteArray?
fun readFile(path: String): ByteArray?
fun readFile(pathComponent: PathComponent, encoding: ContentEncoding): String?
fun readFile(path: String, encoding: ContentEncoding): String?

Returns the contents of the file located at path as ByteArray.

common
fun readFile(path: String): ByteArray?

Returns the contents of the file located at pathComponent. The content is parsed according to encoding. For binary files, use encoding = ContentEncoding.Base64.

common
fun readFile(pathComponent: PathComponent, encoding: ContentEncoding): String?

Returns the contents of the file located at pathComponent. The content is parsed according to encoding. For binary files, use encoding = ContentEncoding.Base64.

js
fun readFile(pathComponent: PathComponent, encoding: ContentEncoding): String?

Returns the contents of the file located at path. The content is parsed according to encoding. For binary files, use encoding = ContentEncoding.Base64.

common
fun readFile(path: String, encoding: ContentEncoding): String?

Returns the contents of the file located at path. The content is parsed according to encoding. For binary files, use encoding = ContentEncoding.Base64.

js
fun readFile(path: String, encoding: ContentEncoding): String?
stat
Link copied to clipboard

Returns stats for the resource at pathComponent.

fun stat(pathComponent: PathComponent): StatResult?
fun stat(pathComponent: PathComponent): StatResult?
fun stat(pathComponent: PathComponent): StatResult?
fun stat(path: String): StatResult?
fun stat(pathComponent: PathComponent): StatResult?
fun stat(path: String): StatResult?

Returns stats for the resource at path.

common
fun stat(path: String): StatResult?

Returns stats for the resource at path.

js
fun stat(path: String): StatResult?
toString
Link copied to clipboard
open override fun toString(): String
open override fun toString(): String
touch
Link copied to clipboard

Creates a file at pathComponent if it does not exist. Returns false if file already exists, otherwise true.

common
fun touch(pathComponent: PathComponent): Boolean
fun touch(pathComponent: PathComponent): Boolean
fun touch(path: String): Boolean
fun touch(pathComponent: PathComponent): Boolean
fun touch(path: String): Boolean

Creates a file at path if it does not exist. Returns false if file already exists, otherwise true.

common
fun touch(path: String): Boolean
unlink
Link copied to clipboard

Removes a file on pathComponent. If it is a directory, its contents are removed as well. Returns true if file is deleted successfully, otherwise false.

common
fun unlink(pathComponent: PathComponent): Boolean
fun unlink(pathComponent: PathComponent): Boolean
fun unlink(path: String): Boolean
fun unlink(pathComponent: PathComponent): Boolean
fun unlink(path: String): Boolean

Removes a file on path. If it is a directory, its contents are removed as well. Returns true if file is deleted successfully, otherwise false.

common
fun unlink(path: String): Boolean
writeFile
Link copied to clipboard

Writes contents to the file located at pathComponent. If create is true, then file is created if it does not exist. Returns true if operation is successful, otherwise false.

common
fun writeFile(pathComponent: PathComponent, contents: ByteArray, create: Boolean): Boolean
fun writeFile(pathComponent: PathComponent, contents: ByteArray, create: Boolean): Boolean
fun writeFile(path: String, contents: ByteArray, create: Boolean): Boolean
fun writeFile(pathComponent: PathComponent, contents: String, create: Boolean, encoding: ContentEncoding): Boolean
fun writeFile(path: String, contents: String, create: Boolean, encoding: ContentEncoding): Boolean
fun writeFile(pathComponent: PathComponent, contents: ByteArray, create: Boolean): Boolean
fun writeFile(path: String, contents: ByteArray, create: Boolean): Boolean
fun writeFile(pathComponent: PathComponent, contents: String, create: Boolean, encoding: ContentEncoding): Boolean
fun writeFile(path: String, contents: String, create: Boolean, encoding: ContentEncoding): Boolean

Writes contents to the file located at path. If create is true, then file is created if it does not exist. Returns true if operation is successful, otherwise false.

common
fun writeFile(path: String, contents: ByteArray, create: Boolean): Boolean

Writes contents to the file located at pathComponent. If create is true, then file is created if it does not exist. For binary files, use encoding = ContentEncoding.Base64. Returns true if operation is successful, otherwise false.

common
fun writeFile(pathComponent: PathComponent, contents: String, create: Boolean, encoding: ContentEncoding): Boolean

Writes contents to the file located at pathComponent. If create is true, then file is created if it does not exist. For binary files, use encoding = ContentEncoding.Base64. Returns true if operation is successful, otherwise false.

js
fun writeFile(pathComponent: PathComponent, contents: String, create: Boolean, encoding: ContentEncoding): Boolean

Writes contents to the file located at path. If create is true, then file is created if it does not exist. For binary files, use encoding = ContentEncoding.Base64.

  • Returns true if operation is successful, otherwise false.

common
fun writeFile(path: String, contents: String, create: Boolean, encoding: ContentEncoding): Boolean

Writes contents to the file located at path. If create is true, then file is created if it does not exist. For binary files, use encoding = ContentEncoding.Base64.

  • Returns true if operation is successful, otherwise false.

js
fun writeFile(path: String, contents: String, create: Boolean, encoding: ContentEncoding): Boolean

Properties

cachesDirectory
Link copied to clipboard

Path to caches directory. Directory is guaranteed to exist (created if not exists already).

val cachesDirectory: Path
val cachesDirectory: Path
val cachesDirectory: Path
val cachesDirectory: Path
contentsDirectory
Link copied to clipboard

Path to the common contents directory. Directory is guaranteed to exist (created if not exists already).

On Android, it points to files directory. On iOS, it points to Documents directory.

val contentsDirectory: Path
val contentsDirectory: Path
val contentsDirectory: Path
val contentsDirectory: Path
temporaryDirectory
Link copied to clipboard

Path to Temporary directory. Directory is guaranteed to exist (created if not exists already).

val temporaryDirectory: Path
val temporaryDirectory: Path
val temporaryDirectory: Path
val temporaryDirectory: Path