FileSystemEntity class - dart:io library (original) (raw)
The common superclass of File, Directory, and Link.
FileSystemEntity objects are returned from directory listing operations. To determine whether a FileSystemEntity is a File, aDirectory, 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 exist both in synchronous and asynchronous versions, 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:
var isThere = await entity.exists();
print(isThere ? 'exists' : 'nonexistent');
Other resources
- The Files and directoriessection of the library tour.
- Write Command-Line Apps, a tutorial about writing command-line apps, includes information about files and directories.
Implementers
Constructors
Properties
A FileSystemEntity whose path is the absolute path of path.
no setter
The hash code for this object.
no setterinherited
Whether this object's path is absolute.
no setter
The parent directory of this entity.
no setter
no setter
A representation of the runtime type of the object.
no setterinherited
A Uri representing the file system entity's location.
no setter
Methods
delete({bool recursive = false})→ Future<FileSystemEntity>
Deletes this FileSystemEntity.
deleteSync({bool recursive = false})→ void
Synchronously deletes this FileSystemEntity.
Checks whether the file system entity with this path exists.
existsSync()→ bool
Synchronously checks whether the file system entity with this path exists.
noSuchMethod(Invocation invocation)→ dynamic
Invoked when a nonexistent 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.
resolveSymbolicLinks()→ Future<String>
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.
Calls the operating system's stat()
function on path.
Synchronously calls the operating system's stat()
function on path.
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
Test if watch is supported on the current system.
no setter
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>
Whether path
refers to a directory.
isDirectorySync(String path)→ bool
Synchronously checks whether path
refers to a directory.
isFile(String path)→ Future<bool>
Whether path
refers to a file.
isFileSync(String path)→ bool
Synchronously checks whether path
refers to a file.
isLink(String path)→ Future<bool>
Whether path
refers to a link.
isLinkSync(String path)→ bool
Synchronously checks whether path
refers to a link.
The parent path of a 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.