我想删除一个带有名称和包含文件夹的文件; 当我说出名字时我的意思是没有扩展名。
这是我所知道的方式。 (在你的帮助下,它会起作用)
//the extension string doesn't work properly.Here I need your help
string extension = Path.GetExtension(@"C:\Projects_2012\Project_Noam\Files\ProteinPic" + comboBox1.SelectedItem.ToString());
string fileLoc = @"C:\Projects_2012\Project_Noam\Files\ProteinPic\" + comboBox1.SelectedItem.ToString() + extension;
if (File.Exists(fileLoc))
{
File.Delete(fileLoc);
}
答案 0 :(得分:2)
您可以使用Directory.GetFiles并使用*
代替扩展程序。
答案 1 :(得分:0)
作为代码的精确翻译,这就是我要写的内容:
string extension = @".txt"; // For example;
string basePath = "@C:\SomePath\";
string pathWithoutExtension = Path.GetExtension(Path.Combine(basePath, comboBox1.Text));
string fullPath = Path.ChangeExtension(pathWithourExtension, extension);
if (!File.Exists(fullPath))
// Do stuff...
else
// Do other stuff...
完成。