Top / Programming / C# Tips / パス文字列からファイル名と拡張子を取得する

パス文字列からファイル名と拡張子を取得する

パス文字列からファイル名と拡張子を取得するには、 System.IO.Path.GetFileName() を使用します。

string path = @"C:\Program Files\Mozilla Firefox\firefox.exe";
string filename = System.IO.Path.GetFileName(path);
Console.WriteLine(filename); // => firefox.exe