-2

我正在尝试更新文件夹中的文件。首先,我需要检查文件夹是否存在,如果不存在,则创建一个,然后在该文件夹中创建一个空文件。如果文件夹不存在,则使用 FailIfExists 或 OpenIfExists 的 CreationCollisionOption 的 try/catch 不起作用。

其他选项:GenerateUniqueName 和 ReplaceExisting 不合适。code:............ //获取存储文件夹 StorageFolder _storageFolder = ApplicationData::Current().LocalFolder();

//get one of it's sub folders
StorageFolder _turboCalc = nullptr; //no default constructor
bool _folderFound = false;
try {
    _turboCalc = co_await _storageFolder.CreateFolderAsync(L"TurboCalc", CreationCollisionOption::OpenIfExists); //create sub folder in sub folde
      //_turboCalc = co_await _storageFolder.CreateFolderAsync(L"TurboCalc", CreationCollisionOption::FailIfExists); //create sub folder in sub folde
}
catch (winrt::hresult_error const& ex) {
    _folderFound = false;
}
StorageFile  _fileDoubles = nullptr; //no default constructor
if (!_folderFound) { //creae the folder and an empty file
    _turboCalc = co_await _storageFolder.CreateFolderAsync(L"TurboCalc");
    _fileDoubles = co_await _turboCalc.CreateFileAsync(L"FileDoubles.dbo", CreationCollisionOption::ReplaceExisting); //create file in sub folder
}
4

1 回答 1

-1

这是协程的行为。问题解决了

于 2018-09-07T15:41:46.823 回答