How do I create a file in a directory structure that does not exist yet in Dart?
dart, dart-io
Solution
Simple code:
import 'dart:io';
void createFileRecursively(String filename) {
// Create a new directory, recursively creating non-existent directories.
new Directory.fromPath(new Path(filename).directoryPath)
.createSync(recursive: true);
new File(filename).createSync();
}
createFileRecursively('foo/bar/baz/bleh.html');
Problem
I want to create a file, say `foo/bar/baz/bleh.html`, but none of the directories `foo`, `foo/bar/`, etc. exist. How do I create my file recursively creating all of the directories along the way?