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

有帮助吗?

解决方案

使用:

File.Exists(path)

微软软件定义网络: http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx

编辑:在系统.IO中

其他提示

系统.IO.文件:

using System.IO;

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

System.IO.File.Exists(路径)

msdn

提供完整路径作为输入。避免相对路径。

 return File.Exists(FinalPath);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top