Skip to content

Instantly share code, notes, and snippets.

@kirillshevch
Created April 13, 2024 15:30
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 kirillshevch/edc30a28e5437e436ece461adc3fed1c to your computer and use it in GitHub Desktop.
Save kirillshevch/edc30a28e5437e436ece461adc3fed1c to your computer and use it in GitHub Desktop.

Fix created timestamps after downloading from Amazon Photos

def adjust_metadata(folder_path)
  pattern = /(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}_\d{3})\.\w+$/

  Dir.foreach(folder_path) do |file|
    next if file == '.' || file == '..'

    match = file.match(pattern)
    if match
      timestamp = match[1]
      full_path = File.join(folder_path, file)

      `exiftool -overwrite_original -DateTimeOriginal=#{timestamp} -FileModifyDate=#{timestamp} -CreateDate=#{timestamp} "#{full_path}"`
      puts "Metadata adjusted for file: #{file}"
    end
  end
end

adjust_metadata('./folder_name')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment