I need to get the directory name from my path, regardless of which one has a backslash. For example, a user can enter one of the following two lines, and I need the name of the log directory:
"C:\Program Files (x86)\My Program\Logs" "C:\Program Files (x86)\My Program\Logs\"
None of the following give the correct answer ( "Logs" ):
Path.GetDirectoryName(m_logsDir); FileInfo(m_logsDir).Directory.Name;
They apparently analyze the path string, and in the first example we decide that Logs is a file, while it really is a directory.
Therefore, he must check whether the last word ( Logs in our case) is really a directory; if yes, return it, if not (logs can also be files), return the parent directory. If you need to process the actual file system, rather than parse the actual string.
Is there any standard feature?
source share