Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.
/ walk Public archive

Directory tree traversal tool in Ruby inspired by python os.walk

License

Notifications You must be signed in to change notification settings

samonzeweb/walk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Directory tree traversal tool in Ruby inspired by python os.walk

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages