filename snippets

Bulk renaming of files

Tagged rename, regexp, bulk, filename, bash, perl, linux  Languages bash

Rename the files in a directory by replacing a space with an underscore. The rename program comes with most modern Linux distros.

rename 's/\ /_/g' *.*

SEO optimizing CarrierWave URLs

Tagged seo, carrierwave, url, filename  Languages apacheconf
class ProductImageUploader < CarrierWave::Uploader::Base

  def store_dir
    "product"
  end

  def filename
    ext = File.extname(original_filename) if original_filename
    "#{model.name.parameterize}#{ext}"
  end
end