Created
April 22, 2017 20:17
-
-
Save ptomato/00d552c4eb58b3ae63d83457770ea1d1 to your computer and use it in GitHub Desktop.
The Mad Scientist Review - GJS Generator Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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