Options
All
  • Public
  • Public/Protected
  • All
Menu

FileManager

FileManager objects can be used to read from or write to files in either the local Drafts app Documents directory (as visible in the Files.app), or iCloud Drive (inside the Drafts folder).

Example

// create a local file in App documents
let fmLocal = FileManager.createLocal(); // Local file in app container
let success = fmLocal.writeString("/ScriptedFile.txt", "This is the file  * content");

// read from file in iCloud
let fmCloud = FileManager.createCloud(); // iCloud
let content = fmCloud.readString("/Test Folder/Test.txt")

// create a directory, and move a file to it
fmCloud.createDirectory("My Folder", "/");
fmCloud.moveItem("/TestFile.txt", "/My Folder/TestFile.txt", false);

Hierarchy

  • FileManager

Index

Properties

lastError

lastError: string | undefined

If a function fails, this property will contain the last error as a string message, otherwise it will be undefined.

Methods

copyItem

  • copyItem(fromPath: string, toPath: string, overwrite?: boolean): boolean
  • Copy file or directory at fromPath to the toPath. From and to path should be complete paths with file names included.

    Parameters

    • fromPath: string
    • toPath: string
    • Optional overwrite: boolean

      If true, replace existing files in at the toPath. If false, abort operation if file exists at destination.

    Returns boolean

createCloud

createDirectory

  • createDirectory(name: string, path: string): boolean
  • Create a directory with the specified name in the specified path. Returns true if directory successfully created.

    Parameters

    • name: string
    • path: string

    Returns boolean

createLocal

listContents

  • listContents(path: string): string[]
  • List files and directories at the specified path. Array of full path will be returned.

    Parameters

    • path: string

    Returns string[]

moveItem

  • moveItem(fromPath: string, toPath: string, overwrite?: boolean): boolean
  • Move file or directory at fromPath to the toPath. From and to path should be complete paths with file names included.

    Parameters

    • fromPath: string
    • toPath: string
    • Optional overwrite: boolean

      If true, replace existing files in at the toPath. If false, abort operation if file exists at destination.

    Returns boolean

readString

  • readString(path: string): string | undefined
  • Reads the contents of the file at the path. Returns undefined value if the file does not exist or could not be read.

    Parameters

    • path: string

      should begin with a / and be relative to the root directory of the FileManager.

    Returns string | undefined

writeString

  • writeString(path: string, content: string): boolean
  • Write the contents of the file at the path. Returns true if successful, false if the file could not be written successfully. This will override existing files!

    Parameters

    • path: string
    • content: string

    Returns boolean

Static create

  • Creates a new FileManager object.

    Parameters

    • isLocal: boolean

      If true, the FileManager will be using the to the local Drafts app documents directory as its root directory, as it appears in the "On my …" area in the Files.app. If false, it will use the Drafts5 iCloud folder as its root directory.

    Returns FileManager

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc