Skip to content

Instantly share code, notes, and snippets.

@ymek
Created November 29, 2012 07:14
Show Gist options
  • Select an option

  • Save ymek/4167324 to your computer and use it in GitHub Desktop.

Select an option

Save ymek/4167324 to your computer and use it in GitHub Desktop.
Capitalize all directory names within a given path
#! /usr/bin/env ruby
##
# Capitalize all directory names within a given path
#
# defaults to the current working directory if no supplied path
base_dir = ARGV[0] || Dir.pwd
Dir.chdir base_dir do
dirs = Dir.glob('*').reject { |f| !File.directory?(f) }
dirs.map(&:downcase).sort!
dirs.each do |dir|
delimiter = dir[/[\W_]/]
parts = dir.split(delimiter).map(&:capitalize)
new_path = File.join(base_dir, parts.join(delimiter))
old_path = File.absolute_path(dir)
File.rename(old_path, new_path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment