C# 取得檔案名稱與副檔名

using System.IO;

string filename = @"C:\test.txt";
//檢查檔案是否存在
if (File.Exists(filename)) {MessageBox.Show("路徑完整名稱 : " + Path.GetFullPath(strPath));
MessageBox.Show("路徑根目錄 : " + Path.GetPathRoot(strPath));
MessageBox.Show("路徑目錄資訊 : " + Path.GetDirectoryName(strPath));
MessageBox.Show("路徑檔案完整名稱 : " + Path.GetFileName(strPath));
MessageBox.Show("路徑檔案名稱 : " + Path.GetFileNameWithoutExtension(strPath));
MessageBox.Show("路徑檔案副檔名 : " + Path.GetExtension(strPath));

}

參考:
https://docs.microsoft.com/zh-tw/dotnet/api/system.io.path?redirectedfrom=MSDN&view=netframework-4.8
https://dotblogs.com.tw/chou/archive/2011/05/30/26625.aspx