finding text files in C# console applications

Status
Not open for further replies.

BobLewiston

In Runtime
Messages
182
In C# console applications, isn't there a simpler way than handling exceptions to just find out if a text file of a given name exists in the current directory? I'm talking about something along the same lines as the following methods:

create text file:
Code:
StreamWriter SW = File.CreateText ("MyFile.txt");
open existing text file:
Code:
StreamReader SR = File.OpenText ("MyFile.txt");
append to text file:
Code:
StreamWriter SW  = File.AppendText ("MyFile.txt");
 
Code:
var getFile = new FileInfo(path);
if (getFile.Exists == true)
{
     // code
}

Like that?
 
Status
Not open for further replies.
Back
Top Bottom