Project

walk

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Directory tree traversal tool inspired by python os.walk
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
~> 2.14
 Project Readme

Walk

Walk is a simple tool to explore a directory tree, inspired by python os.walk. For each directory (and subdirectories) it give path, files and directories.

During the exploration, it don't go down into unreadable directories, and ignore content which have disappeared.

Unlike python walk, there is no error callback (now).

Usage

The Walk.walk function require at least the root of the tree to explore. It can be used with a code block which is called for each directory and receiving 3 arguments : the full path of the current directory, the directories, and the files inside the current directory.

require 'walk'
 
Walk.walk('/') do |path, dirs, files|
  puts "In #{path} there are #{dirs.length} directories and #{files.length} files"
end

Without a block, Walk.walk return an enumerator :

require 'walk'

# Directories containing a least 10 files
puts Walk.walk('/')
  .select { |path,dirs,files| files.length>=10 }
  .map { |path,_,_| path }

Optional (keywords) arguments are :

  • topdown : when true (default) the content is returned from top to bottom during tree exploration. When topdown is false, the content is returned beginning with the bottom.
  • followlinks : when false (default) it doesn't explore subdirectories which are symbolic links. When followlinks is true, it can produce an infinite loop in some cases.

Licence

Walk is released under the MIT license. See LICENSE.txt file for details.