Page 1 of 1

Delete duplicate in root folder, but keep in subfolder

PostPosted: Thu Apr 16, 2026 2:51 pm
by andycatana
Hi everyone,

I’m trying to set up a Hazel rule but I can’t get it to work and could really use some help.

What I want to achieve:

I have a main folder with multiple subfolders. Sometimes the same file exists both in the main (root) folder and in one of the subfolders.

My goal is:
• If a file exists in both the root folder and any subfolder,
→ delete (or move) the one in the root folder

but always keep the version inside the subfolder

Important:
• Only files in the root folder should be affected
• Files inside subfolders should never be deleted or modified
• Matching by filename is sufficient for my use case

I haven’t been able to figure out a reliable way to do this in Hazel and I’m a bit stuck.

Is there a clean way to achieve this with Hazel rules, or would I need to use a script? If a script is required, I’d really appreciate a simple example and how to set it up correctly in Hazel.

Thanks a lot in advance!

Re: Delete duplicate in root folder, but keep in subfolder

PostPosted: Fri Apr 17, 2026 8:34 am
by Mr_Noodle
You might be able to rig something up with nested conditions though this one does seem a bit tricky. The main problem is see is that while you can setup a condition to match based on subfiles, the rule overall has to match a folder and not another file.

You might be able to do something convoluted like tag a folder if it contains a file that also exists in the current folder and then match the file if there's a folder in the same folder with that tag.