如何获取 Unity 中 Firebase 文件夹中所有子文件夹的名称?
How to get names of all subfolders in a Firebase folder in Unity?
在我的 Firebase 存储中,文件层次结构是这样的:
Folder
- Subfolder1
- File1
- File2
- Subfolder2
- File1
- File2
- File3
- Subfolder3
- File1
- File2
等...
所以我想要的是,我想将主文件夹中的子文件夹的名称获取到一个数组中。所以数组看起来像:
folderNamesArray = ["Subfolder1", "Subfolder2", "Subfolder3"]
有谁知道这样做的方法吗?我尝试查看文档,但未能在相关主题下找到任何解决方案
你从 DataSnapshot.Value
in your case is an IDictionary<string, object>
so you could probably simply get all IDictionary<TKey, TValue>.Keys
中得到什么,并将它们转换成一个数组,如
using System.Linq;
...
string[] folderNames = snapshot.Value.Keys.ToArray();
或者如果您更想要这些的实际快照,您可以简单地使用 DataSnapshot.Children
using System.Linq;
...
DataSnapshot[] folders = snapshot.Children.ToArray();
// And then if needed you could still do
string[] folderNames = folders.Select(f => f.Key).ToArray();
在我的 Firebase 存储中,文件层次结构是这样的:
Folder
- Subfolder1
- File1
- File2
- Subfolder2
- File1
- File2
- File3
- Subfolder3
- File1
- File2
等...
所以我想要的是,我想将主文件夹中的子文件夹的名称获取到一个数组中。所以数组看起来像:
folderNamesArray = ["Subfolder1", "Subfolder2", "Subfolder3"]
有谁知道这样做的方法吗?我尝试查看文档,但未能在相关主题下找到任何解决方案
你从 DataSnapshot.Value
in your case is an IDictionary<string, object>
so you could probably simply get all IDictionary<TKey, TValue>.Keys
中得到什么,并将它们转换成一个数组,如
using System.Linq;
...
string[] folderNames = snapshot.Value.Keys.ToArray();
或者如果您更想要这些的实际快照,您可以简单地使用 DataSnapshot.Children
using System.Linq;
...
DataSnapshot[] folders = snapshot.Children.ToArray();
// And then if needed you could still do
string[] folderNames = folders.Select(f => f.Key).ToArray();