i wrote this script to find empty folders and delete them. I want to know:
how to delete folders which are not empty but only have “.DS_Store” file in them
--script to find empty folders and delete them
set pathoffolder to alias "Leopard:Users:lance:Desktop"
--change folder here
tell application "Finder"
set foldernames to name of every folder in pathoffolder
repeat with aItem in foldernames
get size of folder aItem
set s to result
--s stores the size of folder
if s = 0 then
move folder aItem to trash
end if
end repeat
end tell
the Finder (unlike System Events) doesn’t consider invisible files
try this
--script to find empty folders and delete them
set pathoffolder to path to desktop
--change folder here
tell application "Finder"
repeat with oneFolder in (get folders of pathoffolder)
if (count items) of oneFolder is 0 then delete oneFolder
end repeat
end tell
thanks a lot.
yes, it does work…but i generally keep all files visible.
is there a way to hide invisible files through the script and make them visible after the empty folders are deleted
yes, but you have to restart the Finder after changing the invisible property
try this instead
--script to find empty folders and delete them
set pathoffolder to path to desktop
--change folder here
tell application "Finder"
repeat with oneFolder in (get folders of pathoffolder)
if (count items) of oneFolder is 0 or ((count items) of oneFolder is 1 and name of item 1 of oneFolder starts with ".") then delete oneFolder
end repeat
end tell
thanks…i will have to be cautious about files that start with “.” -----i mean in external drives. like ipod or my ceillphone’s memory card…they all have some important invisible files with “.”
but mostly the count would be more than 1 in those cases