B
belmontpress
I wish to delete some files from a directory after reading them but
have the problem that the system says that the files are in use and
cannot delete them even though I have set the StreamReader to null:
DirectoryInfo di = new DirectoryInfo(@"C:\test\");
FileInfo[] fiArray = di.GetFiles("*.txt");
foreach (FileInfo fi in fiArray)
{
Console.WriteLine (fi.Name);
StreamReader sr = new StreamReader(fi.FullName);
sr = System.IO.File.OpenText(fi.FullName);
sr.Close();
sr = null;
fi.Delete();
}
Am I missing something??
have the problem that the system says that the files are in use and
cannot delete them even though I have set the StreamReader to null:
DirectoryInfo di = new DirectoryInfo(@"C:\test\");
FileInfo[] fiArray = di.GetFiles("*.txt");
foreach (FileInfo fi in fiArray)
{
Console.WriteLine (fi.Name);
StreamReader sr = new StreamReader(fi.FullName);
sr = System.IO.File.OpenText(fi.FullName);
sr.Close();
sr = null;
fi.Delete();
}
Am I missing something??