我正在檢查一個文件是否存在,如果是這樣,我把它放在一個列表中,否則我從列表中刪除。我的代碼是這樣的:File.exists顯示文件,即使它不存在
foreach (KeyValuePair<string, string> kvp in dict)
{
_savedxml.Add(kvp.Key.ToString());
}
string namewithext=null;
for (int i = 0; i < _savedxml.Count; i++)
{
namewithext = string.Concat(_savedxml[i], ".xml");
System.IO.FileInfo file_info = new System.IO.FileInfo((string)namewithext);
long size = file_info.Length;
if (size == 0)
{
_savedxml.RemoveAt(i);
}
}
for (int i = 0; i < _savedxml.Count; i++)
{
if (System.IO.File.Exists(System.IO.Path.GetFullPath(namewithext)))
{
}
else
{
_savedxml.Remove(namewithext);
}
}
我試過很多方法,但即使文件不存在,列表中也包含它。我可能犯了一個愚蠢的錯誤。
我該怎麼做?
是什麼'System.IO.Path.GetFullPath(namewithext)'的返回值?這個文件在哪裏(網絡共享...)? – Yahia