I must add that the behavior is not only counter-intuitive, it actually violates the documentation
* @param recursive - If `true`, delete folders under this folder recursively, if `false` the folder needs to be empty.
I made the following workaround
const rmdirOriginal = app.vault.adapter.rmdir;
app.vault.adapter.rmdir = async function(normalizedPath, recursive) {
if (!recursive) {
const abstractFile = app.vault.getAbstractFileByPath(normalizedPath);
if (abstractFile instanceof customJS.obsidian.TFolder) { // COMMENT1
if (abstractFile.children.length > 0) {
throw new Error(`Directory ${normalizedPath} is not empty`);
}
recursive = true;
}
}
await rmdirOriginal.call(this, normalizedPath, recursive);
};
Note that in COMMENT1 I had to use customJS to get access to TFolder class. Unfortunately obsidian API doesn’t give an easy way to access obsidian module. Raised an issue about this before.