Skip to content

Instantly share code, notes, and snippets.

@ptomato
Created April 22, 2017 20:17
Show Gist options
  • Save ptomato/00d552c4eb58b3ae63d83457770ea1d1 to your computer and use it in GitHub Desktop.
Save ptomato/00d552c4eb58b3ae63d83457770ea1d1 to your computer and use it in GitHub Desktop.
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