Skip to content

Instantly share code, notes, and snippets.

@maiha
Created November 13, 2016 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maiha/d99212c573b33cc3a4e716bb733079aa to your computer and use it in GitHub Desktop.
Save maiha/d99212c573b33cc3a4e716bb733079aa to your computer and use it in GitHub Desktop.
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