dir_walker
The Dir::Walker
module supports the top-down traversal of a set of directories.
It is similar to the standard method Dir.glob("**/*")
, but has additional features like skip specific subdirectories, change the sort-oder of directory-listing (default: by name) or optionally ignore errors (IO::Error).
The sourcecode is a port of the Ruby standard lib Find
.
The feature generally is also available in many other languages. Examples are:
* Find.find(...) # Ruby
* os.walk(...) # Python
* File::Find.find(...) # Perl
* filepath.Walk(...) # Go
Installation
- Add the dependency to your
shard.yml
:
dependencies:
dir_walker:
github: 4ndyfix/dir_walker
- Run
shards install
Usage
For example, to total the size of all files under your home directory, ignoring anything in a "dot" directory (e.g. $HOME/.ssh):
require "dir_walker"
total_size : Int64 = 0
Dir::Walker.walk(ENV["HOME"]) do |path|
if File.directory? path
if File.basename(path).starts_with?(".")
Dir::Walker.prune_path # Don't look any further into this directory.
end
else
total_size += File.size(path)
end
end
puts total_size.humanize
Contributing
- Fork it (https://github.com/4ndyfix/dir_walker/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- 4ndyfix - creator and maintainer