Skip to content

Instantly share code, notes, and snippets.

@searls
Created September 28, 2016 02:51
Show Gist options
  • Save searls/a06d402bcef529888ddd2d680be406c7 to your computer and use it in GitHub Desktop.
Save searls/a06d402bcef529888ddd2d680be406c7 to your computer and use it in GitHub Desktop.
#! /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