Created
April 30, 2015 10:27
-
-
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.
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/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