检查文件/目录是否存在:有没有更好的办法?是否存在、办法、文件、目录

由网友(刘老汉*)分享简介:我觉得自己这样做有很多只是为了确保文件名不使用。有没有更好的办法?Directory.Exists(名)|| File.Exists(名)解决方案 肯定的:)内部静态布尔FileOrDirectoryExists(字符串名称){返程(Directory.Exists(名称)|| File.Exists(名称));}...

我觉得自己这样做有很多只是为了确保文件名不使用。有没有更好的办法?

  Directory.Exists(名)|| File.Exists(名)
 

解决方案

肯定的:)

 内部静态布尔FileOrDirectoryExists(字符串名称)
{
   返程(Directory.Exists(名称)|| File.Exists(名称));
}
 

查看pdf文件的目录和添加标签的方法

I find myself doing this a lot just to ensure the filename is not in use. Is there a better way?

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

解决方案

Sure :)

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

阅读全文

相关推荐

最新文章