如何找出C#/ .NET中是否存在文件?

时间:2020-03-05 18:46:17  来源:igfitidea点击:

我想在C#中测试包含文件路径的字符串是否存在(类似于Perl中的-e测试或者Python中的os.path.exists())。

解决方案

回答

使用:

File.Exists(path)

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

编辑:在System.IO

回答

System.IO.File.Exists(路径)

msdn

回答

System.IO.File:

using System.IO;

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