Dart accessing the name of a File or Directory

dart

Solution

You can use the path package to do that :

import 'package:path/path.dart' as path;
main() {
  path.basename('path/to/foo.dart'); // -> 'foo.dart'
  path.basename('path/to');          // -> 'to'
}

See the path package documentation for more explanations.

Problem

How do I read the name of a File or a Directory? There is a property 'path' but that returns the entire file path. Would be nice to have a property like 'name' that just returns the last part of the path. In Java there is a method called File.name();

Original source