Get full path without filename from path that includes filename

前端 未结 6 1089
深忆病人
深忆病人 2020-12-12 21:27

Is there anything built into System.IO.Path that gives me just the filepath?

For example, if I have a string

@\"c:\

6条回答
  •  醉话见心
    2020-12-12 22:09

    I used this and it works well:

    string[] filePaths = Directory.GetFiles(Path.GetDirectoryName(dialog.FileName));
    
    foreach (string file in filePaths)
    {   
        if (comboBox1.SelectedItem.ToString() == "")
        {
            if (file.Contains("c"))
            {
                comboBox2.Items.Add(Path.GetFileName(file));
            }
        }
    }
    

提交回复
热议问题