FileSystemEntity abstract class

The common super class for File, Directory, and Link objects.

FileSystemEntity objects are returned from directory listing operations. To determine if a FileSystemEntity is a File, a Directory, or a Link perform a type check:

if (entity is File) (entity as File).readAsStringSync();

You can also use the type or typeSync methods to determine the type of a file system object.

Most methods in this class occur in synchronous and asynchronous pairs, for example, exists and existsSync. Unless you have a specific reason for using the synchronous version of a method, prefer the asynchronous version to avoid blocking your program.

Here's the exists method in action:

entity.exists().then((isThere) {
  isThere ? print('exists') : print('non-existent');
});

Other resources

  • Dart by Example provides additional task-oriented code samples that show how to use various API from the Directory class and the File class, both subclasses of FileSystemEntity.

  • I/O for Command-Line Apps, a section from A Tour of the Dart Libraries covers files and directories.

  • Write Command-Line Apps, a tutorial about writing command-line apps, includes information about files and directories.

Implemented by

Static Properties

isWatchSupportedbool
read-only

Test if watch is supported on the current system.

Static Methods

identical(String path1, String path2) → Future<bool>

Checks whether two paths refer to the same object in the file system. Returns a Future<bool> that completes with the result.

identicalSync(String path1, String path2) → bool

Synchronously checks whether two paths refer to the same object in the file system.

isDirectory(String path) → Future<bool>

Checks if type(path) returns FileSystemEntityType.DIRECTORY.

isDirectorySync(String path) → bool

Synchronously checks if typeSync(path) returns FileSystemEntityType.DIRECTORY.

isFile(String path) → Future<bool>

Checks if type(path) returns FileSystemEntityType.FILE.

isFileSync(String path) → bool

Synchronously checks if typeSync(path) returns FileSystemEntityType.FILE.

Checks if type(path, followLinks: false) returns FileSystemEntityType.LINK.

isLinkSync(String path) → bool

Synchronously checks if typeSync(path, followLinks: false) returns FileSystemEntityType.LINK.

parentOf(String path) → String

Removes the final path component of a path, using the platform's path separator to split the path. Will not remove the root component of a Windows path, like "C:\" or "\\server_name\". Ignores trailing path separators, and leaves no trailing path separators.

type(String path, { bool followLinks: true }) → Future<FileSystemEntityType>

Finds the type of file system object that a path points to. Returns a Future<FileSystemEntityType> that completes with the result.

typeSync(String path, { bool followLinks: true }) → FileSystemEntityType

Synchronously finds the type of file system object that a path points to. Returns a FileSystemEntityType.

Constructors

FileSystemEntity()

Properties

absoluteFileSystemEntity
read-only

Returns a FileSystemEntity whose path is the absolute path to this. The type of the returned instance is the type of this.

isAbsolutebool
read-only

Returns a bool indicating whether this object's path is absolute.

parentDirectory
read-only

The directory containing this.

pathString
read-only
uriUri
read-only

Returns a Uri representing the file system entity's location.

hashCodeint
read-only, inherited

The hash code for this object.

runtimeTypeType
read-only, inherited

A representation of the runtime type of the object.

Operators

operator ==(other) → bool
inherited

The equality operator.

Methods

delete({bool recursive: false }) → Future<FileSystemEntity>

Deletes this FileSystemEntity.

deleteSync({bool recursive: false }) → void

Synchronously deletes this FileSystemEntity.

exists() → Future<bool>

Checks whether the file system entity with this path exists. Returns a Future<bool> that completes with the result.

existsSync() → bool

Synchronously checks whether the file system entity with this path exists.

rename(String newPath) → Future<FileSystemEntity>

Renames this file system entity. Returns a Future<FileSystemEntity> that completes with a FileSystemEntity instance for the renamed file system entity.

renameSync(String newPath) → FileSystemEntity

Synchronously renames this file system entity. Returns a FileSystemEntity instance for the renamed entity.

Resolves the path of a file system object relative to the current working directory, resolving all symbolic links on the path and resolving all .. and . path segments.

resolveSymbolicLinksSync() → String

Resolves the path of a file system object relative to the current working directory, resolving all symbolic links on the path and resolving all .. and . path segments.

stat() → Future<FileStat>

Calls the operating system's stat() function on the path of this FileSystemEntity. Identical to FileStat.stat(this.path).

statSync() → FileStat

Synchronously calls the operating system's stat() function on the path of this FileSystemEntity. Identical to FileStat.statSync(this.path).

watch({int events: FileSystemEvent.ALL, bool recursive: false }) → Stream<FileSystemEvent>

Start watching the FileSystemEntity for changes.

noSuchMethod(Invocation invocation) → dynamic
inherited

Invoked when a non-existent method or property is accessed.

toString() → String
inherited

Returns a string representation of this object.

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-io/FileSystemEntity-class.html