c# - 检查文件/目录是否存在 : is there a better way?

标签 c# .net file

我发现自己经常这样做只是为了确保文件名未被使用。有没有更好的办法?

Directory.Exists(name) || File.Exists(name)

最佳答案

当然 :)

internal static bool FileOrDirectoryExists(string name)
{
   return (Directory.Exists(name) || File.Exists(name));
}

关于c# - 检查文件/目录是否存在 : is there a better way?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2570930/

相关文章:

c# - Azure session 缓存错误

java - 如何在 Java 中按 Enter 键进入文件

c - system() 输出到 char*

.net - 如何完全序列化/反序列化 RSAParameters 对象

java - 当到达某个字符时中断 while 循环

c# - 对 UPS 跟踪 Rest 服务进行 API 调用时获取 "Authentication failed because the remote party has closed the transport stream."

c# - 这两个片段严格等效吗?

c# - 基于 Azure 服务总线订阅中的系统属性的 SQLFilter

.net - 建模项目问题

c# - .NET GZipStream 解压缩生成空流