我有此代码:

openFileDialog1.Filter = "csv files (*.dbf)|*.dbf";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.FileName = "";

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
   dbf_File = openFileDialog1.FileName;
}

在dbf_File中,我获得了所有文件路径和名称(c:\MyDir\MyFile.dbf)

我只需要名称-MyFile.dbf

最佳答案

仅文件名(带扩展名):

dbf_File = System.IO.Path.GetFileName(dbf_File);

仅包含目录:
string dbf_Path = System.IO.Path.GetDirectoryName(dbf_File);

关于c# - 如何只获取没有文件路径的文件名?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7659210/

10-12 02:57