Skip to content

Instantly share code, notes, and snippets.

@branan
Created May 24, 2012 05:24
Show Gist options
  • Save branan/2779618 to your computer and use it in GitHub Desktop.
Save branan/2779618 to your computer and use it in GitHub Desktop.
require 'yaml'
def dir_to_array(dir)
entries = []
Dir.entries(dir).each do |entry|
if entry == "." or entry == ".."
next
end
p "#{dir}/#{entry}"
if File.directory?("#{dir}/#{entry}")
entries.push({ "#{entry}" => dir_to_array("#{dir}/#{entry}")})
else
entries.push entry
end
end
return entries
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