Skip to content

Instantly share code, notes, and snippets.

@randomecho

randomecho/underscored.rb

Last active Jan 18, 2016
Embed
What would you like to do?
mv folders to have underscore prefix
#!/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