I have a problem specific to Windows.Storage build for HoloLens 2 (ARM64). Tested on HoloLens 1 (x86) with no sight of any kind of problems.
Here is the problem: The GetFilesAsync method returns an empty collection without considering the presence of files in the specified 'KnownFolders' directory. The same is for the method GetItemsAsync (not tested for folders).
When the method GetFileAsync() was used to load an existing file in the same 'KnownFolders' directory the result was correct.
Configuration:
Here is a reprex:
private async Task<string[]> GetNames()
{
StorageFolder storageFolder = KnownFolders.Objects3D;
IReadOnlyList<StorageFile> files = await storageFolder.GetFilesAsync();
string[] names = files.Select(f => f.Name).ToArray();
return names;
}
Thank you for any suggestions in advance.
We reproduced this issue when accessed the Object3D folder and we think it is due to not really expecting to have some non-model file types in the Object3D folder for HoloLens OS. We do have a solution thought that gets a query result object that contains the files which meet the criteria in the current folder and calls the GetFilesAsync method of the query result to get the flat list of files. Here is the answer:
StorageFolder objects3DFolder = KnownFolders.Objects3D;
// Set query options with filter and sort order for results
List<string> fileTypeFilter = new List<string>();
// Determines which file types to include in query results.
fileTypeFilter.Add(".txt");
var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);
var query = KnownFolders.Objects3D.CreateFileQueryWithOptions(queryOptions);
var files = await query.GetFilesAsync();
Debug.WriteLine($"The count of collection is via files.Count :{files.Count}");
StorageFile file = await objects3DFolder.GetFileAsync("bb.txt");
if (file!=null)
{
Debug.WriteLine($"Find the specified file {file.Name} successfully");
}