There are a few too many examples to copy in to here. Accounting for the exceptions could include using one of the file functions to check if the result is a valid directory. The pages of examples show you what happens and what to do if you expect simple names to be page names. That is what happens on most of the sites I fix.
Someone supplies a page name without a directory name.
It is different on some site. People and programs supply directory names one minute then page names another time. I have to confirm the meaning via a file function. All rights reserved.