Skip to main content

Posts

Showing posts from February, 2021

Dart: List directory recursively (tree, ls)

Dart: List directory recursively (tree, ls) ls(String where, [String prefix]) { if(prefix == null) { prefix = ''; } var dir = new Directory(where); print(where); List contents = dir.listSync(); for (var fileOrDir in contents) { if (fileOrDir is File) { print(fileOrDir.path); } else if (fileOrDir is Directory) { print(fileOrDir.path); ls(fileOrDir.path, prefix + '-'); } } }