renaming new file overwrites existing file

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

Moderator: Mr_Noodle

renaming new file overwrites existing file Wed Jan 11, 2017 7:42 am • by robodean
scenario:
inside a folder I am watching there is a file, inside that file is a door...no wait. that's the matrix.

ok, imagine there is:
file.ext
I then export to the folder an new version of the file, but it is named:
file-a.ext
I want hazel to strip the new file of the suffix "-a" so that it becomes:
file.ext
but as there is already a file.ext, it creates an incremented version:
file-1.ext
which I do not want

is there a way, when renaming a file, that if a file already exists with the same name, the previously existing file is deleted BEFORE renaming the new file, so no incremented "duplicate" is created? Essentially I want to overwrite the existing file with the new one when it is renamed.

much obliged.
robodean
 
Posts: 20
Joined: Tue Aug 14, 2007 12:20 pm

The best way would be for the original program to overwrite it if possible. If not, it's a bit tricky. You'd need to do something like:
Code: Select all
If (all) are met
    Name matches (•filename)
    If (all) are met for (the enclosing folder)
        If (all) are met for (any of its sub-files)
            Name matches (•filename)-(letter)
Do
    Move to trash


where •filename is set to match anything.

What this does is look for a sibling file which has the same name plus a dash plus a letter. It then throws the file away. You may need to tweak this a bit but that should get you going in the right direction.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

will give it a try
thanks
robodean
 
Posts: 20
Joined: Tue Aug 14, 2007 12:20 pm


Return to Support