I have a custom button on ribbon for document library and need to disable it if current SPListItem is an empty folder.
To disable button I use EnabledScript attribute of CommandUIHandler. I can get current SP.ListItem in JS COM by next code:
var clientContext = new SP.ClientContext();
var list = clientContext.get_web().get_lists().getById({ListID});
var item = list.getItemById({ItemID});
And then I can detect if item is folder or file by its SP.ListItem.fileSystemObjectType Property
var fsoType = item.get_fileSystemObjectType();
And in case of File I can get file by SP.ListItem.file property. But I can't get SP.Folder if fsoType is Folder. How could I get it?
Then simply I could check SP.Folder.files and SP.Folder.folders roperties.