Created
December 26, 2011 15:43
-
-
Save mnem/1521462 to your computer and use it in GitHub Desktop.
Script to look in each subfolder containing ebook files and select the 'best' candidates for chucking on an iPad
This file contains hidden or 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" | |
output_folder_name = "_ipad_selection" | |
output = File.expand_path File.join(Dir.pwd, output_folder_name) | |
selected = [] | |
# Gather folders to look at | |
folders = Dir.glob(%w{*/*.epub */*.pdf}).map {|file| File.dirname file} | |
folders.delete_if { | item | item.match(/^#{output_folder_name}/)} | |
folders.uniq! | |
# Make sure the output directory exists | |
Dir.mkdir output unless File.exists? output | |
# Copy the best file versions in | |
folders.each { | |
| folder | | |
epubs = Dir.glob(File.join(folder, "*.epub")) | |
pdfs = Dir.glob(File.join(folder, "*.pdf")) | |
chosen = epubs.length > 0 ? epubs : pdfs | |
chosen.each { | |
| file | | |
target = File.join output, File.basename(file) | |
if File.exists? target | |
puts "Skipping '#{file}' because it's already in the output folder" | |
else | |
FileUtils.cp file, output | |
end | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment