取得檔案名稱與副檔名

C#:
string filename = @"C:\test.txt";

if (File.Exists(filename)) {
    MessageBox.Show("取得檔名(不包含附檔名)" + Path.GetFileNameWithoutExtension(filename));
    MessageBox.Show("取得副檔名:" + Path.GetExtension(filename));
    MessageBox.Show("資料根目錄:" + Path.GetPathRoot(filename));
    MessageBox.Show("取得路徑:" + Path.GetFullPath(filename));
}

VB:

    Dim filename As String = "C:\test.txt"

    If File.Exists(filename) Then
        MessageBox.Show("取得檔名(不包含附檔名)" & Path.GetFileNameWithoutExtension(filename))
        MessageBox.Show("取得副檔名:" & Path.GetExtension(filename))
        MessageBox.Show("資料根目錄:" & Path.GetPathRoot(filename))
        MessageBox.Show("取得路徑:" & Path.GetFullPath(filename))
    End If

留言

熱門文章