UWP applications don't have direct access to any of the file system except:
- Read-only non-exclusive access to the package install folder
- Read/write access to an application data folder (roaming or local)
- Read/write to a private temp folder.
All other access is mediated through Windows Runtime 'brokers'.
One solution is to use Windows Runtime APIs to copy the entire file to a temporary folder and then use std::filesystem
on the temporary copy.
Here's an example using the pictures folder:
#include "winrt/Windows.Storage.h"
#include "winrt/Windows.Storage.Pickers.h"
using namespace winrt::Windows::Storage;
using namespace winrt::Windows::Storage::Pickers;
FileOpenPicker openPicker;
openPicker.ViewMode(PickerViewMode::Thumbnail);
openPicker.SuggestedStartLocation(PickerLocationId::PicturesLibrary);
openPicker.FileTypeFilter().Append(L".jpg");
openPicker.FileTypeFilter().Append(L".png");
auto file = co_await openPicker.PickSingleFileAsync();
if (file)
{
auto tempFolder = ApplicationData::Current().TemporaryFolder();
auto tempFile = co_await file.CopyAsync(tempFolder, file.Name(), NameCollisionOption::GenerateUniqueName);
if (tempFile)
{
std::filesystem::path file = LR"(tempFile.Path().c_str())";
...
DeleteFile(tempFile.Path().c_str());
}
}
See Microsoft Docs