Last active
September 8, 2015 13:22
-
-
Save IcyApril/9b875d2c75414166c361 to your computer and use it in GitHub Desktop.
A Ruby script to extract WordPress uploads without resized images.
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/local/bin/ruby -w | |
# A Ruby script to extract WordPress uploads, excluding resized images, into a single directory. | |
# File names will be prepended with the directory #string. | |
# RUN: ruby wpmediaexport.rb >> wpmediaexport.sh | |
# THEN REVIEW/RUN: ./wpmediaexport.sh | |
# Generated shell script will be in wpmediaexport.sh. | |
# Cd into the uploads directory in WordPress before running. | |
# Make sure you create an empty img directory prior to running wpmediaexport.sh | |
# wpmediaexport.sh needs permission to run, thus you might need to run chmod +x wpmediaexport.sh. | |
puts "#!/bin/bash" | |
files = Dir.glob("**/*") | |
files.each do |item| | |
next if item == '.' or item == '..' | |
next if item == 'wpmediaexport.rb' or item == 'wpmediaexport.sh' | |
noext = File.basename(item) | |
base = File.basename(item,File.extname(item)) | |
afterdash = base.partition('-').last | |
dirname = File.dirname(item) | |
dirnamestripped = 'img/'+dirname.gsub('/', '').gsub('.', '') | |
if File.file?(item) | |
if afterdash.empty? | |
puts "cp "+item+" "+dirnamestripped+noext | |
else | |
if afterdash !~ /[0-9]+x[0-9]+/ | |
puts "cp "+item+" "+dirnamestripped+noext | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment