Created
September 28, 2016 02:51
-
-
Save searls/a06d402bcef529888ddd2d680be406c7 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# Moves all the files found by the glob into a new directory of the same name | |
# as the file (less its extension). Useful when you have a bunch of examples | |
# in one language and you need to introduce multiple sibling examples to sit | |
# alongside the file | |
# | |
# Example usage: | |
# $ ruby folderify.rb "smells/**/*.js" | |
require 'fileutils' | |
Dir[glob_pattern = ARGV[0]].each do |f| | |
next unless File.file?(f) | |
new_dir = File.join(File.dirname(f), File.basename(f, ".*")) | |
FileUtils.mkdir_p(new_dir) | |
FileUtils.mv(f, new_dir) | |
puts "Moved #{f} to #{new_dir}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment