How do you handle "~" in a path string with dart -
i'm unaware on how make "~" expand using path. expect using path functions, directory/file class automatically handle it.
import "dart:io"; import 'package:path/path.dart'; void main() { print(absolute("~")); var d = new directory("~"); print(d.absolute.path); }
prints
/private/tmp/dummy/dummy/bin/~ /private/tmp/dummy/dummy/bin/~
this depends on situation. in example can use following code.
import "dart:io"; import "package:file_utils/file_utils.dart"; void main() { var home = filepath.expand("~/music"); var dir = new directory(home); print(dir.absolute.path); }
if want find files can use code.
import "package:file_utils/file_utils.dart"; void main() { var songs = fileutils.glob("~/music/*{.mp3,.flac}"); for(var song in songs) { print(song); } }
Comments
Post a Comment