Files
pixes/lib/utils/io.dart
2024-05-13 09:36:23 +08:00

22 lines
427 B
Dart

import 'dart:io';
extension FSExt on FileSystemEntity {
Future<void> deleteIfExists() async {
if (await exists()) {
await delete();
}
}
int get size {
if (this is File) {
return (this as File).lengthSync();
} else if(this is Directory){
var size = 0;
for(var file in (this as Directory).listSync()){
size += file.size;
}
return size;
}
return 0;
}
}