Skip to content

Instantly share code, notes, and snippets.

@ptomato

ptomato/leafnode.js

Created Apr 22, 2017
Embed
What would you like to do?
The Mad Scientist Review - GJS Generator Example
const Gio = imports.gi.Gio;
function* leafnodes(file) {
let enumerator = file.enumerate_children('standard::*', 0, null);
let info;
while ((info = enumerator.next_file(null))) {
let child = enumerator.get_child(info);
if (info.get_file_type() === Gio.FileType.DIRECTORY)
yield* leafnodes(child);
else
yield child.get_basename();
}
}
let file = Gio.File.new_for_commandline_arg(ARGV[0]);
for (let leaf of leafnodes(file))
print(leaf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment