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


当前回答

Use:

File.Exists(path)

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

编辑:在系统中。IO

其他回答

System.IO.File:

using System.IO;

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

Use:

File.Exists(path)

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

编辑:在系统中。IO

System.IO.File.Exists(路径)

msdn

File.Exists(Path.Combine(_workDir, _file));

给出完整路径作为输入。避免相对路径。

 return File.Exists(FinalPath);