Created
June 13, 2019 07:41
-
-
Save numbata/0de2cdd5ddba4484041fe7401fd7b1ea to your computer and use it in GitHub Desktop.
Revisions
-
numbata created this gist
Jun 13, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ require 'pathname' def rwalk(path) current_directory = Pathname.new(path) breadcrumbs = [[current_directory, Dir.foreach(current_directory)]] Enumerator.new do |y| loop do current_directory, current_iterator = breadcrumbs.last begin fname = current_iterator.next rescue StopIteration breadcrumbs.pop break if breadcrumbs.empty? next end next if fname == '.' || fname == '..' fullpath = current_directory.join(fname) if File.file?(fullpath) y << fullpath else breadcrumbs << [fullpath, Dir.foreach(fullpath)] end next end end end