Ignore subfolder, if parent folder has spaces

I cant figure out how to ignore subfolders, if a parent folder has spaces in the name.

Examples:

path result
subfolder/ does work
folder/subfolder/ does work
folder with spaces/subfolder/ does not work
folder with spaces/ does work!
folder\ with\ spaces/subfolder/ does not work
“folder with spaces/subfolder/” does not work
‘folder with spaces/subfolder/’ does not work

I have this specific use case because I have multiple subfolders with the same name. Thus I can’t just exclude the subfolder.
How can I ignore a folder, if the parent folder has spaces?