Search code examples
applescriptsubdirectoryfinder

Delete sub folders of current folder with applescript


I have this simple applescsript:

tell application "Finder"
set xfolder to target of Finder window 1
move files of entire contents of xfolder to xfolder
end tell

which will move every file in subfolders of current folder to the parent folder.

I want it to also remove this subfolders after the files are moved.

Can't get it to work...


Solution

  • If by "remove" you mean put the folders in the trash, then this should work.

    Keep in mind that there's no error correction here, so (for example) if there are files with duplicate names in the hierarchy, the resulting error will kill the script.

    tell application "Finder"
        set xfolder to target of Finder window 1
        move files of entire contents of xfolder to xfolder
        delete folders of entire contents of xfolder
    end tell