Giter Site home page Giter Site logo

walk's Introduction

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.

walk's People

Contributors

samonzeweb avatar

Stargazers

Beyar avatar Mark Gibbons  avatar

Watchers

 avatar Mark Gibbons  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.