C# Newbie - Having a problem
I have a test file located here: C:\test.txt
I am trying to see if the file exists:
bool exists;
exists = System.IO.File.Exists(@"c:\test.txt");
exists always returns false even though the file does exist
the same thing happens if I try using:
System.IO.File.Delete(@"c:\test.txt");
even thought he file exists, it is never deleted.
Am I missing something?
What is the purpose of the @ symbol before the file name?
Thanks
Scott LyslePosted Mar 25, 2007, 10:27 AM
if
(!System.IO.File.Exists(@"C:\alabama-seal.jpg"))MessageBox.Show("It is NOT there");
else
MessageBox.Show("It IS there");
System.IO.
File.Delete(@"C:\alabama-seal.jpg"); if (!System.IO.File.Exists(@"C:\alabama-seal.jpg"))MessageBox.Show("It is NOT there");
else
MessageBox.Show("It IS there");
As expected, the first message box said "It IS there", the file was then deleted and the second message box said "It is NOT there."
A check of the root file shows the file was in fact deleted.
Scott LyslePosted Mar 25, 2007, 10:20 AM
As for usage of the File.Exists method; this works fine:
if
(!System.IO.File.Exists("C:\\Temp\\somefile.txt"))MessageBox.Show("It is NOT there");
else
MessageBox.Show("It IS there");
And so does this:
if
(!System.IO.File.Exists(@"C:\Temp\al_outline.gif"))MessageBox.Show("It is NOT there");
else
MessageBox.Show("It IS there");