Skip to content

Instantly share code, notes, and snippets.

@jm3
Forked from searls/folderify.rb
Created September 28, 2016 11:44
Show Gist options
  • Save jm3/417c802e90f440ab308e1c23df1f9037 to your computer and use it in GitHub Desktop.
Save jm3/417c802e90f440ab308e1c23df1f9037 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