Skip to content

Instantly share code, notes, and snippets.

@mnutt
Last active April 17, 2020 00:37
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 mnutt/298114250571ae708a8881edb689d44c to your computer and use it in GitHub Desktop.
Save mnutt/298114250571ae708a8881edb689d44c to your computer and use it in GitHub Desktop.
Generate CSV of file created/modified times
# USAGE:
# 1. Save this file to your Desktop (Cmd-S, click Desktop in the left sidebar)
# 2. Open Terminal.app (Cmd-space, type "terminal", hit enter)
# 3. Type this, exactly: ruby ~/Desktop/created-times.rb
# 4. You should see some output about checking directories and how many files were loaded.
# 5. A media-.......csv file will appear on your Desktop, which can be loaded with Excel
require 'time'
extensions = ["jpg", "jpeg", "mov", "heic", "mp4"]
directories = ["Pictures", "Movies"]
files = directories.map { |directory|
extensions.map { |extension|
to_check = File.join(ENV['HOME'], directory, '**', "*.#{extension}")
puts "Checking #{to_check}"
Dir.glob(to_check)
}
}.flatten
outfile = "media-#{Time.now.to_i}.csv"
File.open(File.join(ENV['HOME'], "Desktop", outfile), "w") do |out|
out.puts "created, modified, filename"
files.each_with_index do |file, i|
puts "Loaded #{i} files" if i % 1000 == 0
stat = File.stat(file)
out.puts [stat.ctime.strftime("%Y-%m-%d %H:%M:%S"),
stat.mtime.strftime("%Y-%m-%d %H:%M:%S"),
file].map{ |col| "\"#{col}\"" }.join(",")
end
end
puts "Wrote #{outfile} to desktop"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment