Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A collection of simple and useful utility methods for operating on directories.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 dir-util.gemspec
README.md

dir-util

dir-util is just a collection of simple and useful utility methods for operating on directories on the filesystem.

Requirements/Installation

dir-util depends on fileutils being available. In test, it relies on rspec and either rcov (Ruby 1.8) or simplecov (Ruby 1.9).

Install the gem: gem install dir-util-(version).gem

Running the tests:

rake spec

Building the gem:

rake gem:build

Install gem with Rake:

rake gem:install

Usage

to_all_files

I've found that I often want to do something to every file contained in a directory tree (ie, in the directory and all its subdirectories, all the way down until all the subdirectories are exhausted).

For example, I recently wrote a program that went through a directory and found all the image files, processed them, and moved them out to another location.

DirUtil.to_all_files("~/Documents") do |filename|
    puts filename
end

The block is passed recursively to every subdirectory.

The way I think about the naming for this one is "to all files do ".

subdirectories

Sometimes you just want to know all the subdirectories under a directory.

DirUtil.subdirectories("~") == ["/Users/sirsean/Documents", "/Users/sirsean/Desktop", "/Users/sirsean/Documents/sub1", "/Users/sirsean/Desktop/sub2"]

The list you get back is ordered such that all the top-level subdirectories come first; basically, if you wanted to delete all the subdirectories, you'd want to reverse the list first.

License

See the LICENSE file. Licensed under the Apache 2.0 License

Something went wrong with that request. Please try again.