Skip to content

Instantly share code, notes, and snippets.

@evolve2k
Created May 10, 2011 08:05
Show Gist options
  • Select an option

  • Save evolve2k/964077 to your computer and use it in GitHub Desktop.

Select an option

Save evolve2k/964077 to your computer and use it in GitHub Desktop.
Rename files in a directory into a slug format
class String #:nodoc:
def to_slug
self.gsub(/ /,"_").gsub(/&/,"and").gsub(/\?|\!|\#/,"").downcase
end
end
files = Dir.glob("*")
files.each { |f| File.rename(f, f.to_slug) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment