Skip to content

Instantly share code, notes, and snippets.

@ninjs
Created April 21, 2015 15:06
Show Gist options
  • Save ninjs/0a5d6c5fc09e3b84f0a4 to your computer and use it in GitHub Desktop.
Save ninjs/0a5d6c5fc09e3b84f0a4 to your computer and use it in GitHub Desktop.
def dir_rename
dir = Dir.open(__dir__)
puts "Renaming folders..."
dir.each do |file|
next if File.file?(file)
if File.directory?(file)
base_name = File.basename(file)
next if base_name.start_with?('11')
next if base_name.start_with?('--')
if base_name.include?(" ")
no_dash = base_name.gsub('-', ' ')
full_name = no_dash.split(/ /)[0..1].join(' ')
File.rename(file, full_name)
else
next
end
end
end
end
dir_rename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment