问题描述
我正在使用Visual Studio 2017将我的桌面应用程序更改为UWP作为visual-studio-2017-update-4-makes-easy-modernize-desktop-application-make-store-ready /的指南。 / p>
根据en-us / library / mt185496.aspx,UWP支持System.IO命名空间。
我们知道,用户的数据不应该写在已安装的文件夹中,而应该位于"Root Drive:\ Users \ username \ AppData \"中漫游" ;.我遵循这条规则。但我遇到了桌面应用程序中从未发生的问题。
private static string EnsureDirectory(string directoryPath)
{
if(!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
return directoryPath;
}
代码很简单。我想在访问之前确保该目录已经存在。目录路径不存在,但Directory.Exists(directoryPath)返回TRUE。我试图省略检查(注释掉检查行)并转到Directory.CreateDirectory(directoryPath),
执行方法时没有任何错误信息,但之后,不创建文件夹。
如何处理这个问题?我是否必须引用Windows.Storage.dll并重写与文件/目录操作相关的所有方法?
I am using Visual Studio 2017 to change my desktop application into UWP as guide in visual-studio-2017-update-4-makes-easy-modernize-desktop-application-make-store-ready/.
As per en-us/library/mt185496.aspx, System.IO namespaces are supported in UWP.
As we know, the user's data should not be written in installed folder and they should be in "Root Drive:\Users\username\AppData\Roaming". I followed this rule. But I encountered an issue never happened in desktop application.
private static string EnsureDirectory(string directoryPath)
{
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
return directoryPath;
}
The code is simple. I want to make sure the directory already existed before I access it. the directory path is not exist but Directory.Exists(directoryPath) returns TRUE. And I tried to omit the check (comment out the checking line) and go to Directory.CreateDirectory(directoryPath), the method is executed without any error information, but after that, the folder is not created.
How to deal with this issue? Do I must reference Windows.Storage.dll and rewrite all methods related to file/directory operations?
这篇关于为什么Directory.Exists返回true但实际上路径不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!