Alex Rivera | Logout

How to find out if a file exists in C# / .NET?

Asked 2008-09-02T07:18:48.120
254

I would like to test a string containing a path to a file for existence of that file (something like the -e test in Perl or the os.path.exists() in Python) in C#.

Edit
Report

1 Answer

82

System.IO.File:

using System.IO;

if (File.Exists(path)) 
{
    Console.WriteLine("file exists");
} 
answered 2008-09-02T07:22:11.997

Your Answer