首页 / 知识

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

2023-04-13 21:33:00

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

How to find out if a file exists in C# / .NET?

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


采用:

1
File.Exists(path)

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

编辑:在System.IO


System.IO.File:

1
2
3
4
5
6
using System.IO;

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


System.IO.File.Exists(路径)

msdn


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

1
 return File.Exists(FinalPath);


文件路径字符串是否存在

最新内容

相关内容

热门文章

推荐文章

标签云

猜你喜欢