FileSystemEntity class Null safety

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

Implementers

Constructors

FileSystemEntity()

Properties

absolute FileSystemEntity
Returns a FileSystemEntity whose path is the absolute path to this. [...]
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
isAbsolute bool
Whether this object's path is absolute. [...]
read-only
parent Directory
The directory containing this.
read-only
path String
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
uri Uri
Returns a Uri representing the file system entity's location. [...]
read-only

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. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
rename(String newPath) Future<FileSystemEntity>
Renames this file system entity. [...]
renameSync(String newPath) FileSystemEntity
Synchronously renames this file system entity. [...]
Resolves the path of a file system object relative to the current working directory. [...]
resolveSymbolicLinksSync() String
Resolves the path of a file system object relative to the current working directory. [...]
stat() Future<FileStat>
Calls the operating system's stat() function on the path of this FileSystemEntity. [...]
statSync() FileStat
Synchronously calls the operating system's stat() function on the path of this FileSystemEntity. [...]
toString() String
Returns a string representation of this object.
inherited
watch({int events: FileSystemEvent.all, bool recursive: false}) Stream<FileSystemEvent>
Start watching the FileSystemEntity for changes. [...]

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited

Static Properties

isWatchSupported bool
Test if watch is supported on the current system. [...]
read-only

Static Methods

identical(String path1, String path2) Future<bool>
Checks whether two paths refer to the same object in the file system. [...]
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. [...]
type(String path, {bool followLinks: true}) Future<FileSystemEntityType>
Finds the type of file system object that a path points to. [...]
typeSync(String path, {bool followLinks: true}) FileSystemEntityType
Synchronously finds the type of file system object that a path points to. [...]