Files w. Similar First 10 Characters > Delete Older One

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hi Hazel Community,

I'm trying to accomplish something and unsure if Hazel 4 is able to do it.

In the instance that I have two files in the same folder:
File 1: AAA.BBB.CCC.S01E01.HDTV.720p.XXX.mp4
File 2: AAA.BBB.CCC.S01E01.WEB-DL.720p.YYY.mp4

Where AAA.BBB.CCC can also be only AAA. or even AAA.BBB.CCC.DDD. and they can combine to be a total of anywhere from 5 to 30 characters. Also probably not relevant but note that File 2 Created and Modified Date is always greater/newer than File 1.

I want Hazel to look at the first 10 characters (may be more or less than 10, until I find the perfect number of characters for the formula) and if two files (i.e. File 1 and File 2) have the same first 10 characters, delete the HDTV (File 1) that is also the older file. There will never be a File 3 as these are weekly TV Show Files and File 1 will move to another folder within 6 days.

Basically since HDTV is always available first and WEB-DL is available within a week or less, send HDTV to the Trash when the WEB-DL version of the episode is added to the folder.

May be I am approaching the problem wrongly and would immensely appreciate if someone could help me out on this. Thank you!
Tekoo
 
Posts: 1
Joined: Mon Oct 31, 2016 2:06 am

This one is a bit tricky. First, search the help for "match patterns".

Also, read this article on nested conditions: https://www.noodlesoft.com/kb/how-to-cr ... onditions/

From there, you'll need to do something like:
Code: Select all
If (all) are met
    Name matches <<<some pattern which matches the filename. You'll need a custom attribute to match the common part of the name. Also, you want to match the HDTV version of the file>>>

    If (all) are met for (the enclosing folder)
        If (all) are met for (any of its sub-files)
            Name matches <<<pattern to match the WEB-DL name. Use the same custom attribute you defined above here to match the first part of the name>>>
Do
    Move to trash


What the above does is match the HDTV file if there is another file with a similar name (depends on the custom attribute you set up) that matches the WEB-DL counterpart. If it matches, it throws the file away. It will need some tweaking but that should outline the basic approach.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support