Deleting Replaced Files

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

Moderator: Mr_Noodle

Deleting Replaced Files Thu Oct 04, 2012 7:58 pm • by joecan
Apologies is this has been covered before, I did my best searching for an answer but came up empty. I'm new to Hazel and I'm still trying to rap my head around all the options. I've been playing with files in a temporary directory to see what all the features do, but there's one thing I want Hazel to do in the future that I just can't figure out.

I have a folder that contain SD video files, and I would like to have Hazel automatically delete that file if a better quality video is added to that directory as a replacement. The files aren't going to be identically named, but will share the same first 20 characters, or so. There are a bunch of HD videos already in the folder with duplicate SD counterparts, and I'd like Hazel to be able to clean that up as well.

Can anyone point me in the right direction?
joecan
 
Posts: 3
Joined: Thu Oct 04, 2012 7:48 pm

Re: Deleting Replaced Files Fri Oct 05, 2012 10:56 am • by Mr_Noodle
I'm a little unsure how the files are named differently but here's a somewhat crazy thing you can try:
Code: Select all
If (all) match for (file being matched)
    Name matches XXXXXXXXX
    If (all) match for (enclosing folder)
        If (all) match for (any subfile)
            Name matches YYYYYYY
Then
    Move to trash


What this rule does is match the file if it matches the lower quality video's name and if it's enclosing folder has a filename that matches the higher quality video (you might have to read that to yourself a couple times). Basically, whether it has a sibling that matches the higher Q video.

Now the tricky part is correlating the low-Q and hi-Q versions while also distinguishing them. Unfortunately, you can't have one match pattern refer to a custom token defined in another. Basically, the way the rule is now, it will match a low-Q file when ANY hi-Q file, not just it's replacement, is in that folder. There might be a way for you to rig this using color labels or separating the files out into their own folders but I suggest you play with it to get an understanding about how the above works.
Mr_Noodle
Site Admin
 
Posts: 11551
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Deleting Replaced Files Fri Oct 05, 2012 2:01 pm • by joecan
What I meant when I said they were named differently, is this... The videos are for old lecture files I have, and some of them are being re-uped to our Uni server in their original format, instead of the bad quality they were previously, I suppose to conserve bandwidth. I've batch renamed the old ones to match the naming format of the newer videos. I just inserted SD, into the quality section:

COURSE TITLE - YYYY-MM-DD - LECTURE TOPIC (Quality)

But if I understand your post correctly, there is no way to compare to similarly named files. Since that's the only way I can think to make it work, maybe what I'm asking is impossible. I don't want to get into an elaborate sub-folder mess where I have folders for every single lecture. But maybe if I just put those old files in folders like that, I could download the higher version into that folder structure. Run that rule you posted, and then move the remaining (hopefully) higher quality version back into the main folder, and delete the sub-folder.

I'm really trying to wrap my brain around all this. Am I heading in the right direction with my ought process?
joecan
 
Posts: 3
Joined: Thu Oct 04, 2012 7:48 pm

Re: Deleting Replaced Files Fri Oct 05, 2012 2:18 pm • by Mr_Noodle
I think you're on the right track. It's easy to sort into subfolder based on the beginning of the file. The alternative is to write a script that can be used in the condition.
Mr_Noodle
Site Admin
 
Posts: 11551
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Deleting Replaced Files Fri Oct 05, 2012 4:12 pm • by joecan
One other question, the XXXXXX & YYYYYY, what do they represent? That's probably a really stupid question, but I'm just learning how all this stuff works, and what the shorthands are in these code examples.
joecan
 
Posts: 3
Joined: Thu Oct 04, 2012 7:48 pm

Re: Deleting Replaced Files Mon Oct 08, 2012 11:13 am • by Mr_Noodle
I left it totally open-ended but they are match patterns (check the help on them). I meant it more abstractly than anything particular that you should follow.
Mr_Noodle
Site Admin
 
Posts: 11551
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron