16
Oct
2006
Rake task to remove the image and audio files created by captcha
To add a rake task to the rails application which removes all the image and audio files created by captcha, create a file named remove_captcha_files.rake in the lib/tasks directory.
Add the following code to the lib/tasks/remove_captcha_files.rake file…
desc "Remove captcha images and audio files"
task :remove_captcha_files do
image_path = "#{RAILS_ROOT}/public/images/captcha/"
audio_path = "#{RAILS_ROOT}/public/captcha_audio/"
Dir.foreach(image_path){|file| File.delete(image_path+file) if (/^.*.jpg$/).match(file)} if File.exist?(image_path)
Dir.foreach(audio_path){|file| File.delete(audio_path+file) if (/^.*.wav$/).match(file)} if File.exist?(audio_path)
puts "Captcha files removed."
end
You can confirm that task is added to your app by running
rake –task
To remove all the files created by captcha, simply run the command
rake remove_captcha_files
from the command line from your application root.
To better view the code visit here


Working with Vinsol has been one of the most rewarding and productive collaborations I've ever had in the technology industry. Manik is an intelligent and honest engineer with a great faculty for open and clear communication, and his team include some of the swiftest and keenest developers I've ever had the pleasure to work with. They're great value for money, excellent people who are a joy to know and interact with, and above all they really know their stuff