Getting the folder name from a path
问题 string path = "C:/folder1/folder2/file.txt"; What objects or methods could I use that would give me a result of folder2 ? 回答1: I would probably use something like: string path = "C:/folder1/folder2/file.txt"; string lastFolderName = Path.GetFileName( Path.GetDirectoryName( path ) ); The inner call to GetDirectoryName will return the full path, while the outer call to GetFileName() will return the last path component - which will be the folder name. This approach works whether or not the path