Page 1 of 1

renaming new file overwrites existing file

PostPosted: 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.

Re: renaming new file overwrites existing file

PostPosted: Wed Jan 11, 2017 3:08 pm
by Mr_Noodle
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.

Re: renaming new file overwrites existing file

PostPosted: Wed Jan 11, 2017 4:52 pm
by robodean
will give it a try
thanks