When I have a path as string what is the simplest way to get information whether the path points to a file or a directory.
import 'dart:io' as io;
void main() {
print(io.Directory.current);
String path = '../console/readline';
var f = new io.File(path);
print('exists: ${f.existsSync()}');
print('file: ${f.statSync().type == io.FileSystemEntityType.FILE}');
print('directory: ${f.statSync().type == io.FileSystemEntityType.DIRECTORY}');
print('link: ${f.statSync().type == io.FileSystemEntityType.LINK}');
print('not found: ${f.statSync().type == io.FileSystemEntityType.NOT_FOUND}');
}
prints for an existing directory
Directory: '/home/user/dart/playground/bin/io/get_entry_type_from_path'
exists: false
file: false
directory: true
link: false
not found: false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With