Applescript to sort similar filenames in a folder - and delete all dupes but the most recent

Trying to sort thru about 1800 files .txt format. About 1/2 of these are dupes. In nearly every case, the filenames are similar between 2-3 files. Looking to build an Applescript that will:


Browse all filenames in a folder and look for similarities between filenames. Typically the first 5-10 characters will be the same.


if at least two files have similar filenames, compare file modification dates


determine which file(s) are older


delete older file(s)


Process all files until done


Ive been reading up on the find command and using its sort attribute, but not getting very far.


Any advice would be great!



Posted on Feb 12, 2019 9:19 AM

Reply

Similar questions

9 replies

Mar 7, 2019 3:01 PM in response to NITEBOATER

AppleScript is not wise choice for that. Try fdupes, or jdupes.


If you need more speed use jdupes, but it do more strict data comparison.


To install them use HomeBrew package manager.


Press Command+Space and type Terminal and press enter/return key.


Run in Terminal app:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null

and press enter/return key. 


If the screen prompts you to enter a password, please enter your Mac's user password to continue. When you type the password, it won't be displayed on screen, but the system would accept it. So just type your password and press ENTER/RETURN key. Then wait for the command to finish.


Run:

brew install fdupes


Run:

brew install jdupes


Feb 17, 2019 12:14 PM in response to rccharles

Hey RC,


That's quite an impressive script. I was however - not able to use it in any case, its far more complicated than my simple requirement. I much appreciate your input in any case. Eventually stumbled on - BBEdit v12 - trial version - was able to help sort things out. It has a function where it can indentify the hash (put in each txt document by the awful Notes app's import function, I needed these gone and BBEdit can do it. Strangely, it does not seem to also be able to delete from its search results, what a PIA. In the end, I had to manually perform routine tasks, even after grepping many files.


Too bad to this date there still is no comprehensive Finder alternative that can search as well as Houdahspot and BBEdit, but also delete according to rules and grep strings, you are just s.0.l apparently. Perhaps I should be the one to tackle SWIFT and encode and build a true solution.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript to sort similar filenames in a folder - and delete all dupes but the most recent

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.