-
-
Save jm3/417c802e90f440ab308e1c23df1f9037 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