Created
November 29, 2012 07:14
-
-
Save ymek/4167324 to your computer and use it in GitHub Desktop.
Capitalize all directory names within a given path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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