Skip to content

Instantly share code, notes, and snippets.

@dpogue
Forked from branan/gist:2779618
Created May 24, 2012 05:33
Show Gist options
  • Save dpogue/2779665 to your computer and use it in GitHub Desktop.
Save dpogue/2779665 to your computer and use it in GitHub Desktop.
require 'yaml'
def dir_to_array(dir)
Dir.entries(dir).reject { |e| ['.', '..'].include? e }.map { |entry|
if File.directory? "#{dir}/#{entry}"
{ "#{entry}" => dir_to_array "#{dir}/#{entry}"}
else
entry
end
}
end
File.open('books.yml', 'wb') do |out|
YAML.dump({"books" => dir_to_array(ARGV[0])}, out)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment