Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.