0

I want to delete (move to trash) all files with ".acr" file extension in the parent and the current folder. I tried it like this:

tell application "Finder"
    try
        delete (every file of folder of (file (path to me)) whose name ends with ".acr")
        delete (every file of container of (file (path to me)) whose name ends with ".acr")
    end try
end tell

Only the files in the current folder are deleted. The files in the parent folder are not deleted.

0

1 Answer 1

1

If, by current folder, you mean the current folder open in Finder, then this will retrieve all .acr files in that folder and its parents folder, then move them to the Trash:

    tell application "Finder" to ¬
        tell front Finder window to if exists then
            set f to (every file of its target ¬
                whose name extension is "acr") as alias list
            set g to (every file of its target's container ¬
                whose name extension is "acr") as alias list

            delete f & g
        end if

If you are actually meaning to implement path to me as you've done in your snippet, then the problem lies in that both folder of... and container of... essentially mean the same thing, therefore both lines of code are looking for files in the same directory: namely, the directory where your script lives, if you're running it from inside Script Editor.

Here's the fix:

    tell application "Finder"
        set f to every file ¬
            of folder ¬
            of (path to me) ¬
            whose name extension is "acr"

        set g to every file ¬
            of container ¬
            of folder ¬
            of (path to me) ¬
            whose name extension is "acr"

        delete f & g
    end tell
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.