Skip to content

Instantly share code, notes, and snippets.

@briandunn
Created January 7, 2010 23:16
Show Gist options
  • Save briandunn/271707 to your computer and use it in GitHub Desktop.
Save briandunn/271707 to your computer and use it in GitHub Desktop.
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