Created
November 13, 2016 09:15
-
-
Save maiha/d99212c573b33cc3a4e716bb733079aa to your computer and use it in GitHub Desktop.
This file contains 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
alias Entry = Hash(Symbol, File::Stat | String) | |
def awalkDir(dir, block : Entry -> Nil) | |
Dir.entries(dir).each do |fname| | |
next if fname == "." || fname == ".." | |
current = File.join(dir, fname) | |
begin | |
s = File.lstat(current) | |
rescue error | |
next | |
end | |
if s.directory? | |
block.call({:dir => dir, :fname => fname, :stat => s }) | |
begin # sometimes directories disappear... | |
awalkDir(current, block) # <-- this causes compile failure | |
rescue error | |
next | |
end | |
else | |
block.call({:dir => dir, :fname => fname, :stat => s }) | |
end | |
end | |
end | |
callback = ->(e : Entry) { puts e } | |
awalkDir("/", callback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment