Question

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#.

Was it helpful?

Solution

Use:

File.Exists(path)

MSDN: http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx

Edit: In System.IO

OTHER TIPS

System.IO.File:

using System.IO;

if (File.Exists(path)) 
{
    Console.WriteLine("file exists");
} 

System.IO.File.Exists(path)

msdn

Give full path as input. Avoid relative paths.

 return File.Exists(FinalPath);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top