Removing empty directories

I’m trying to clean up empty directories in a nested folder structure.
The following code isn’t working reliably:

for each f as FolderItem in folder.Children
  if f.IsFolder and f.Count > 0 then
  end if
  if f.IsFolder and f.Count = 0 then
  end if

I thought perhaps Folderitem.Count also counts hidden files but I don’t see any when I view hidden files.

Is there a better approach?

You may be running up against the .DS_Store files that the Finder creates when you view a folder. I’ve taken to deleting that first and then the folder.