Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@evandhoffman
Created April 30, 2015 10:27
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 evandhoffman/a645210aee89ee451cac to your computer and use it in GitHub Desktop.
Save evandhoffman/a645210aee89ee451cac to your computer and use it in GitHub Desktop.
Script to consolidate all the .MOV files on my computer into a single directory, organized by YYYY/YYYY-MM/YYYY-MM-DD.filename.mov dir structure.
#!/usr/local/Cellar/ruby/2.1.5/bin/ruby
#
#
require 'fileutils'
base_dir = ARGV[0]
target_dir = ARGV[1]
movies = Dir.glob([base_dir, '**','*.mov'].join('/'))
counter = 0
movies.each do |movie|
counter += 1
# next unless counter < 100
f = File.new(movie)
new_path = [ target_dir, f.mtime.strftime("%Y/%Y-%m/%Y-%m-%d/%Y-%m-%d")].join('/')
FileUtils.mkdir_p (new_path) unless File.exists?(new_path)
new_path += '.' + File.basename(f)
printf("%04d: Renaming %s to %s\n", counter, f.path, new_path)
FileUtils.mv(f, new_path, :verbose => true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment