I am trying to extract the directory from a path that may or may not contain the file name. The problem is that when I am trying to get the directory name of a path that is already a directory, the Path.GetDirectoryName() returns the upper level of that dir. The path is loaded from the database so I cannot check the file attributes.
Ex. Path.GetDirectoryName("D:\Work\Project\Sources\trunk\Project2\bin\Debug") returns "D:\Work\Project\Sources\trunk\Project2\bin\"
I was thinking of a simple algorithm, that checks if the path contains the "." character; if yes, then we are dealing with a path that contains the file name. Unfortunately the directory names can also contain the "." character.
I know that there is no perfect solution for this issue but what is the next best thing?
There is already a Stackoverflow question about the issue but it assumes that the file or directory already exists.