Created
December 26, 2011 15:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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