本文介绍了检查文件/目录是否存在:有没有更好的办法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我觉得自己这样做有很多只是为了确保文件名不使用。有没有更好的办法?
Directory.Exists(名)|| File.Exists(名)
解决方案
肯定的:)
内部静态布尔FileOrDirectoryExists(字符串名称)
{
返程(Directory.Exists(名称)|| File.Exists(名称));
}
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));
}
这篇关于检查文件/目录是否存在:有没有更好的办法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!