• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Finder - Delete empty folders, recursively
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finder - Delete empty folders, recursively


  • Subject: Re: Finder - Delete empty folders, recursively
  • From: Graff <email@hidden>
  • Date: Mon, 14 Jun 2004 19:25:34 -0400

You should be careful when using this example script. Although it does work just fine there exists the possibility that it will fail on folders that have a deep hierarchy, that is they have a lot of folders nested inside folders.

However it does help in one matter, it will go directly to the deepest folders and then back out. So if you delete a folder and that's all that was in the parent then you can delete the parent also. This can be a bit tricky with other solutions.

Here's the modified example:
----
tell application "Finder"
set theFolder to (folder of the front window)
my ClearEmptyFolder(theFolder)
end tell

on ClearEmptyFolder(whatsPassed)
tell application "Finder"
set theFolders to folders of whatsPassed
repeat with aFolder in theFolders
my ClearEmptyFolder(aFolder)
end repeat
if ((count every item of whatsPassed) = 0) then
display dialog "deleting " & name of whatsPassed
end if
end tell
end ClearEmptyFolder
----

- Ken

On Jun 14, 2004, at 2:42 PM, Paul Kampu wrote:

Hello all!

Here is a script that very nicely deletes every file from every folder
within the parent, recursively. (don't know who wrote this script)


tell application "Finder"
set theRealFolder to (folder of the front window)
my dumpFiles(theRealFolder)
end tell

on dumpFiles(whatsPassed)
tell application "Finder"
delete every file of whatsPassed
set folderContents to (every item of whatsPassed)
repeat with anItem in folderContents
my dumpFiles(anItem)
end repeat
end tell
end dumpFiles


Now the question is...
Does anyone have some idea as to how to modify this script to delete the
EMPTY folders only? ie. Leave the folders containing files alone.
Or is it better to start from scratch? If so, any suggestions?
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Finder - Delete empty folders, recursively
      • From: Graff <email@hidden>
References: 
 >Finder - Delete empty folders, recursively (From: Paul Kampu <email@hidden>)

  • Prev by Date: Re: [ANN] MathWallah beta testers please
  • Next by Date: Re: [ANN] MathWallah beta testers please
  • Previous by thread: Finder - Delete empty folders, recursively
  • Next by thread: Re: Finder - Delete empty folders, recursively
  • Index(es):
    • Date
    • Thread