0.0
No commit activity in last 3 years
No release in over 3 years
FileCrawler searches and controls files in local directory
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 10.0
~> 3.0
 Project Readme

FileCrawler

Gem-version Build Status

Installation

Add this line to your application's Gemfile:

gem 'file_crawler'

And then execute:

$ bundle

Or install it yourself as:

$ gem install file_crawler

Usage

  • Create Instance
finder = FileCrawler::Finder.new
  • Find directories
path = '.'

finder.search(path)
p finder.directories #=> ["./bin", "./lib", "./spec", ...]
p finder.dirs #=> ["./bin", "./lib", "./spec", ...] # directories's shortname

finder.search(path, maxdepth: 1)
p finder.dirs #=> ["./bin", "./lib", "./spec"]

finder.search(path, maxdepth: 1, grep: 'sample')
p finder.dirs #=> []
  • Create groups per label decided by directory name
# collect use `directories`
# directories = ['/path/path1/[abcd] defg', '/path/path2/(abcd) defg', '/path/path1/test 123', ...
finder.collect(regexs: ['[]', '()'])
p finder.collections
#=> { 'abcd': ['/path/path1/[abcd] defg', '/path/path2/(abcd) defg'], 'test 123': ['/path/path1/test 123'], ... }
  • Move directory to destination
# move use `directories` or `collections`
# files = #=> ["./bin", "./lib", ...]
destination = '/var'
finder.move(destination)

# ensure destination
# [ [from, to], ... ]
p finder.targets #=> [["./bin", "/var/bin"] , ["./lib", "/var/lib"], ...]

# command output
p finder.output_mv #=> [ "mv ./bin /var/bin", "mv ./lib /var/lib", ...]

# run
finder.move(destination, dry_run: false)
  • Chain
finder.search(source, grep: 'sample').collect(regexs: ['[]']).move(destination)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hirohisa/file_crawler.

License

The gem is available as open source under the terms of the MIT License.