这似乎没有意义,所以我显然做错了什么:
DirectoryInfo folder = new DirectoryInfo(Environment.CurrentDirectory + @"\Test");
if (folder.Exists == false) {
folder.Create();
var doesItExists = folder.Exists;
}
如果文件夹不存在,则创建该文件夹。除了doesItExists
总是假的。如果我刚刚创建它为什么会是错误的?
中的值folder.Exists
is cached https://github.com/dotnet/corefx/blob/f2e440450e8b52317f08c21fe66f70141c9e933c/src/System.IO.FileSystem/src/System/IO/DirectoryInfo.cs#L117。我建议做这个检查:
var doesItExists = Directory.Exists(folder.FullName);
或者你可以打电话folder.Refresh()
在创建目录后检查目录是否存在之前更新缓存。看到这个之前的回答 https://stackoverflow.com/a/8331673/188246.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)