0

その名前とそれを含むフォルダーを含むファイルを削除したい。私が名前を言うとき、私は拡張子なしを意味します。

これが私が知っている方法です。(あなたの少しの助けで、それはうまくいきます)

//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);
}
4

2 に答える 2

2

Directory.GetFilesを使用して*、拡張子の代わりにan を使用できます。

于 2012-05-16T15:30:21.720 に答える
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...

終わり。

于 2012-05-16T15:35:55.303 に答える