Created
November 4, 2022 18:41
-
-
Save jcdavison/9a839a6abc2ac07a61e90180e9ae1ad7 to your computer and use it in GitHub Desktop.
remove duplicate heic from list of photos
This file contains hidden or 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
| require 'pry' | |
| # get all file names | |
| file_names = Dir.entries(".") | |
| # .entries(".") is annoying as it will also return ".", ".." which will give us problems | |
| complete_file_names = Dir.entries(".").select {|entry| File.file? entry } | |
| # general logic | |
| # | |
| # Dir.entries(".").grep /1864/ | |
| # => ["IMG_1864.JPG", "IMG_1864.HEIC"] | |
| # grab the name | |
| # search the entire list, if there are two files with same name but different extension, destroy the heic | |
| files_to_delete = [] | |
| complete_file_names.each do |file_name| | |
| base_file_name = file_name.split(".")[0] | |
| possible_pairs = complete_file_names.grep Regexp.new base_file_name | |
| if possible_pairs.include? "#{base_file_name}.HEIC" | |
| if possible_pairs.include? "#{base_file_name}.JPG" | |
| files_to_delete.push("#{base_file_name}.HEIC") | |
| end | |
| end | |
| end | |
| files_to_delete.sort.uniq.each do |file_to_delete| | |
| File.delete(file_to_delete) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment