deleteIfExists static method
Deletes a FileSystemEntity by entityPath
, only if it exists.
If entityPath
is a directory, it is deleted recursively.
Returns true
if the entityPath
doesn't exist or was deleted,
otherwise false
.
Implementation
static bool deleteIfExists(String entityPath) {
try {
if (FileSystemEntity.isDirectorySync(entityPath)) {
final dir = Directory(entityPath);
if (dir.existsSync()) dir.deleteSync(recursive: true);
} else {
final file = File(entityPath);
if (file.existsSync()) file.deleteSync();
}
} on FileSystemException catch (_) {
return false;
}
return true;
}