Skip to content

Instantly share code, notes, and snippets.

@randomecho
Last active January 18, 2016 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomecho/102cba5ebf588c282762 to your computer and use it in GitHub Desktop.
Save randomecho/102cba5ebf588c282762 to your computer and use it in GitHub Desktop.
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