1

当我将路径作为字符串时,获取路径是否指向文件或目录的信息的最简单方法是什么。

4

1 回答 1

2
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}');
}

打印现有目录

Directory: '/home/user/dart/playground/bin/io/get_entry_type_from_path'
exists: false
file: false
directory: true
link: false
not found: false
于 2014-08-20T10:43:03.243 回答