Walk down a directory to label (and reveal) zero byte files

_count is not working and I’m not sure why. :/

The walkFolder() function is recursive, so be careful where you choose to run this. Made to help identify corrupt old archives that have been copied (and copied) from Mac to WINDOWS to CDs and back.

on walkFolder(f, _count)
list folder f
repeat with i in the result
set _item to (alias (f & i))
if folder of (info for _item) then
walkFolder(f & i & ":", _count)
else
if first character of i is not "." then
if size of (info for _item) is 0 then
tell application "Finder"
set label index of _item to 7 -- Gray. Perhaps adding a spotlight comment would be better...
reveal _item -- Comment this out if you expect a lot of results.
end tell
set _count to _count + 1
end if
end if
end if
end repeat
return _count
end walkFolder

on run {}
set _count to 0
try
tell application "Finder" to set cwd to folder of window 1 as alias
on error
set cwd to path to desktop folder
end try
set theFolder to (choose folder "Select a folder to list:" default location cwd) as string
my walkFolder(theFolder, _count)
display dialog (_count as text) & " files found to be 0 bytes" giving up after 600
end run

Apologies for formatting errors as I’m editing this post on Safari from OS X 10.5 which doesn’t work well with WordPress’ auto-drafting.

Leave a Reply

Your email address will not be published. Required fields are marked *