【问题标题】:How can I tell from a path string whether it is a file or a directory如何从路径字符串中判断它是文件还是目录
【发布时间】:2014-08-20 10:41:51
【问题描述】:

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

【问题讨论】:

    标签: dart dart-io


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 2021-06-22
      • 1970-01-01
      • 2010-09-13
      • 1970-01-01
      • 2012-07-17
      • 2010-11-03
      • 1970-01-01
      • 2017-05-01
      • 2013-04-28
      相关资源
      最近更新 更多