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)
How about checking whether FileAttributes == -1?
public static bool PathExists(this string path) {
DirectoryInfo dirInfo = null;
try { dirInfo = new DirectoryInfo(path.TrimEnd(Path.DirectorySeparatorChar)); }
catch { }
if (dirInfo == null || dirInfo.Attributes == (FileAttributes)(-1))
return false;
return true;
}