Dart API Referencedart:ioDirectory

Directory abstract class

Directory objects are used for working with directories.

abstract class Directory {
  /**
   * Creates a directory object. The path is either an absolute path,
   * or it is a relative path which is interpreted relative to the directory
   * in which the Dart VM was started.
   */
  factory Directory(String path) => new _Directory(path);

  /**
   * Creates a directory object from a Path object. The path is either
   * an absolute path, or it is a relative path which is interpreted
   * relative to the directory in which the Dart VM was started.
   */
  factory Directory.fromPath(Path path) => new _Directory.fromPath(path);

  /**
   * Creates a directory object pointing to the current working
   * directory.
   */
  factory Directory.current() => new _Directory.current();

  /**
   * Check whether a directory with this name already exists. Returns
   * a [:Future<bool>:] that completes with the result.
   */
  Future<bool> exists();

  /**
   * Synchronously check whether a directory with this name already exists.
   */
  bool existsSync();

  /**
   * Creates the directory with this name. If the directory already
   * exists nothing is done. Returns a [:Future<Directory>:] that
   * completes with this directory once it has been created. If the
   * directory does not exist and cannot be created the future
   * completes with an exception.
   */
  Future<Directory> create();

  /**
   * Synchronously creates the directory with this name. If the
   * directory already exists nothing is done. If the directory does
   * not exist and cannot be created an exception is thrown.
   */
  void createSync();

  /**
   * Creates a temporary directory with a name based on the current
   * path.  This name and path is used as a template, and additional
   * characters are appended to it by the call to make a unique
   * directory name.  If the path is the empty string, a default
   * system temp directory and name are used for the template.
   *
   * Returns a [:Future<Directory>:] that completes with the newly
   * created temporary directory.
   */
  Future<Directory> createTemp();

  /**
   * Synchronously creates a temporary directory with a name based on the
   * current path. This name and path is used as a template, and additional
   * characters are appended to it by the call to make a unique directory name.
   * If the path is the empty string, a default system temp directory and name
   * are used for the template. Returns the newly created temporary directory.
   */
  Directory createTempSync();

  /**
   * Deletes the directory with this name. The directory must be
   * empty. Returns a [:Future<Directory>:] that completes with
   * this directory when the deletion is done.
   */
  Future<Directory> delete();

  /**
   * Synchronously deletes the directory with this name. The directory
   * must be empty. Throws an exception if the directory cannot be
   * deleted.
   */
  void deleteSync();

  /**
   * Deletes this directory and all sub-directories and files in the
   * directories. Returns a [:Future<Directory>:] that completes with
   * this directory when the deletion is done.
   */
  Future<Directory> deleteRecursively();

  /**
   * Synchronously deletes this directory and all sub-directories and
   * files in the directories. Throws an exception if the directory
   * cannot be deleted.
   */
  void deleteRecursivelySync();

  /**
   * Rename this directory. Returns a [:Future<Directory>:] that completes
   * with a [Directory] instance for the renamed directory.
   *
   * If newPath identifies an existing directory, that directory is
   * replaced. If newPath identifies an existing file the operation
   * fails and the future completes with an exception.
   */
  Future<Directory> rename(String newPath);

  /**
   * Synchronously rename this directory. Returns a [Directory]
   * instance for the renamed directory.
   *
   * If newPath identifies an existing directory, that directory is
   * replaced. If newPath identifies an existing file the operation
   * fails and an exception is thrown.
   */
  Directory renameSync(String newPath);

  /**
   * List the sub-directories and files of this
   * [Directory]. Optionally recurse into sub-directories. Returns a
   * [DirectoryLister] object representing the active listing
   * operation. Handlers for files and directories should be
   * registered on this DirectoryLister object.
   */
  DirectoryLister list({bool recursive: false});

  /**
   * Gets the path of this directory.
   */
  final String path;
}

Constructors

factory Directory(String path) #

Creates a directory object. The path is either an absolute path, or it is a relative path which is interpreted relative to the directory in which the Dart VM was started.

factory Directory(String path) => new _Directory(path);

factory Directory.current() #

Creates a directory object pointing to the current working directory.

factory Directory.current() => new _Directory.current();

factory Directory.fromPath(Path path) #

Creates a directory object from a Path object. The path is either an absolute path, or it is a relative path which is interpreted relative to the directory in which the Dart VM was started.

factory Directory.fromPath(Path path) => new _Directory.fromPath(path);

Properties

final String path #

Gets the path of this directory.

final String path;

Methods

Future<Directory> create() #

Creates the directory with this name. If the directory already exists nothing is done. Returns a Future<Directory> that completes with this directory once it has been created. If the directory does not exist and cannot be created the future completes with an exception.

Future<Directory> create();

void createSync() #

Synchronously creates the directory with this name. If the directory already exists nothing is done. If the directory does not exist and cannot be created an exception is thrown.

void createSync();

Future<Directory> createTemp() #

Creates a temporary directory with a name based on the current path. This name and path is used as a template, and additional characters are appended to it by the call to make a unique directory name. If the path is the empty string, a default system temp directory and name are used for the template.

Returns a Future<Directory> that completes with the newly created temporary directory.

Future<Directory> createTemp();

Directory createTempSync() #

Synchronously creates a temporary directory with a name based on the current path. This name and path is used as a template, and additional characters are appended to it by the call to make a unique directory name. If the path is the empty string, a default system temp directory and name are used for the template. Returns the newly created temporary directory.

Directory createTempSync();

Future<Directory> delete() #

Deletes the directory with this name. The directory must be empty. Returns a Future<Directory> that completes with this directory when the deletion is done.

Future<Directory> delete();

Future<Directory> deleteRecursively() #

Deletes this directory and all sub-directories and files in the directories. Returns a Future<Directory> that completes with this directory when the deletion is done.

Future<Directory> deleteRecursively();

void deleteRecursivelySync() #

Synchronously deletes this directory and all sub-directories and files in the directories. Throws an exception if the directory cannot be deleted.

void deleteRecursivelySync();

void deleteSync() #

Synchronously deletes the directory with this name. The directory must be empty. Throws an exception if the directory cannot be deleted.

void deleteSync();

Future<bool> exists() #

Check whether a directory with this name already exists. Returns a Future<bool> that completes with the result.

Future<bool> exists();

bool existsSync() #

Synchronously check whether a directory with this name already exists.

bool existsSync();

DirectoryLister list([bool recursive = false]) #

List the sub-directories and files of this Directory. Optionally recurse into sub-directories. Returns a DirectoryLister object representing the active listing operation. Handlers for files and directories should be registered on this DirectoryLister object.

DirectoryLister list({bool recursive: false});

Future<Directory> rename(String newPath) #

Rename this directory. Returns a Future<Directory> that completes with a Directory instance for the renamed directory.

If newPath identifies an existing directory, that directory is replaced. If newPath identifies an existing file the operation fails and the future completes with an exception.

Future<Directory> rename(String newPath);

Directory renameSync(String newPath) #

Synchronously rename this directory. Returns a Directory instance for the renamed directory.

If newPath identifies an existing directory, that directory is replaced. If newPath identifies an existing file the operation fails and an exception is thrown.

Directory renameSync(String newPath);