Last active
January 18, 2016 03:14
-
-
Save randomecho/102cba5ebf588c282762 to your computer and use it in GitHub Desktop.
mv folders to have underscore prefix
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 | |
# | |
# mv folders to have underscore prefix | |
# | |
# Author:: Soon Van - randomecho.com | |
# Copyright:: Copyright 2016 Soon Van | |
# License:: http://opensource.org/licenses/BSD-3-Clause | |
require 'FileUtils' | |
@total_count = 0 | |
def underscored(path_to) | |
Dir.foreach(path_to) do |dir| | |
full_path = path_to + dir | |
new_path = path_to + '__' + dir | |
if dir[0,1] != '.' && File.directory?(full_path) | |
FileUtils.mv(full_path, new_path) | |
puts "mv #{full_path} -> #{new_path}" | |
@total_count += 1 | |
end | |
end | |
end | |
#Gem.win_platform? ? (system "cls") : (system "clear") | |
if ARGV[0].nil? | |
puts "! No folder specified." | |
puts "Use the following format: \n\n" | |
puts "$ #{File.basename(__FILE__)} /path/to" | |
exit | |
else | |
underscored(ARGV[0]) | |
if @total_count > 0 | |
puts "Total moved: #{@total_count}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment