如何返回文件所在的文件夹名?   Path中没有直接找到,请指点一下

解决方案 »

  1.   

    //目录的完全路径
    Console.WriteLine(new System.IO.FileInfo(@"C:\windows\system32\user32.dll").DirectoryName);
    //目录名
    Console.WriteLine(new System.IO.FileInfo(@"C:\windows\system32\user32.dll").Directory.Name);
      

  2.   


            //
            // 摘要:
            //     返回指定路径字符串的目录信息。
            //
            // 参数:
            //   path:
            //     文件或目录的路径。
            //
            // 返回结果:
            //     包含 path 目录信息的 System.String;或者为 null(如果 path 表示根目录、是空字符串 ("") 或是 null)。如果
            //     path 没有包含目录信息,则返回 System.String.Empty。
            //
            // 异常:
            //   System.ArgumentException:
            //     path 参数包含无效字符、为空、或仅包含空白。
            //
            //   System.IO.PathTooLongException:
            //     path 参数的长度超过系统定义的最大长度。
    System.IO.Path.GetDirectoryName( string path);