Created
January 7, 2010 23:16
-
-
Save briandunn/271707 to your computer and use it in GitHub Desktop.
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
desc 'partition photo ids' | |
task :partition_photo_ids => :environment do | |
for p in Photo.all | |
base_path = p.data.path.split(p.id.to_s).first | |
orig_path = base_path + p.id.to_s | |
if FileTest.directory?( orig_path ) | |
new_path = base_path + ("%09d" % p.id).scan(/\d{3}/).join("/") | |
`mkdir -p #{new_path} && mv #{orig_path}/* #{new_path} && rmdir #{orig_path}` | |
else | |
p.destroy | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment