Skip to content

Instantly share code, notes, and snippets.

@mnem
Created December 26, 2011 15:41
Show Gist options
  • Save mnem/1521457 to your computer and use it in GitHub Desktop.
Save mnem/1521457 to your computer and use it in GitHub Desktop.
Script to move and group all ebook files in the current folder into a pretty named subfolder.
#!/usr/bin/env ruby
require "fileutils"
folder_map = {}
def make_folder_name name
return name.gsub /_/, " "
end
# Gather all the files in this directory
Dir.glob(%w{*/*.epub */*.pdf */*.apk */*.zip}) {
| item |
foldername = make_folder_name File.basename(item, File.extname(item))
folder_map[foldername] ||= []
folder_map[foldername].push item
}
# Move everything
folder_map.each {
| folder, books |
Dir.mkdir folder unless File.exists? folder
books.each { |book| FileUtils.mv book, folder }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment