How can I get the name of a file in Dart?

dart, file

Solution

You can use the path package :

import 'dart:io';
import 'package:path/path.dart';

main() {
  File file = new File("/dev/dart/work/hello/app.dart");
  String filename = basename(file.path);
}

Problem

I found I can't get the name of a file in a simple way :( Dart code: ``` File file = new File("/dev/dart/work/hello/app.dart"); ``` How to get the file name `app.dart`? I don't find an API for this, so what I do is: ``` var path = file.path; var filename = path.split("/").last; ``` Is there any simpler solution?

Original source