Skip to content

Instantly share code, notes, and snippets.

@bhollis
Created August 31, 2013 03:43
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 bhollis/6396105 to your computer and use it in GitHub Desktop.
Save bhollis/6396105 to your computer and use it in GitHub Desktop.
Simple script for moving files to another directory while preserving their folder structure.
#!/usr/bin/env ruby
# Usage: deepmv '**/*.rb' ../other
#
# Moves files under the current directory matching a glob
# to another directory, preserving directory structure.
require 'fileutils'
glob = ARGV.shift
dest = ARGV.shift
Dir.glob(glob) do |f|
destfile = File.join(dest, f)
FileUtils.mkdir_p File.dirname(destfile)
FileUtils.mv f, destfile
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment