我想在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中
using System.IO;
if (File.Exists(path))
{
Console.WriteLine("file exists");
}
System.IO.File.Exists(路径)
提供完整路径作为输入。避免相对路径。
return File.Exists(FinalPath);