StorageItemTypes 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public enum class StorageItemTypes
/// [System.Flags]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
enum class StorageItemTypes
[System.Flags]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public enum StorageItemTypes
var value = Windows.Storage.StorageItemTypes.none
Public Enum StorageItemTypes
- 继承
-
StorageItemTypes
- 属性
Windows 要求
设备系列 |
Windows 10 (在 10.0.10240.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
|
字段
File | 1 | 表示为 StorageFile 实例的文件。 |
Folder | 2 | 表示为 StorageFolder 实例的文件夹。 |
None | 0 | 既不是文件也不是文件夹的存储项。 |
示例
以下示例演示如何通过调用 GetItemsAsync () 方法获取当前文件夹中的文件和子文件夹。 然后,该示例循环访问每个 IStorageItem 并调用 IStorageItem.IsOfType 方法,以确定每个项是文件还是文件夹。
using Windows.Storage;
using System.Threading.Tasks;
using System.Diagnostics; // For writing results to Output window.
// Get the app's installation folder.
StorageFolder appFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
// Get the files and folders in the current folder.
IReadOnlyList<IStorageItem> itemsInFolder = await appFolder.GetItemsAsync();
// Iterate over the results and print the list of items
// to the Visual Studio Output window.
foreach (IStorageItem item in itemsInFolder)
{
if(item.IsOfType(StorageItemTypes.Folder))
Debug.WriteLine("Folder: " + item.Name);
else
Debug.WriteLine("File: " + item.Name + ", " + item.DateCreated);
}
注解
此枚举中的值由 IStorageItem.IsOfType、 StorageFile.IsOfType 和 StorageFolder.IsOfType 方法返回。
IsOfType 方法可用于处理返回可以是文件或文件夹的 IStorageItem 实例的方法的结果。 例如, GetItemAsync 和 GetItemsAsync 方法返回 IStorageItem 实例。 若要处理返回的项,请调用 IStorageItem 接口的 IsOfType 方法,以确定每个项是文件还是文件夹。 然后将项强制转换为 StorageFolder 或 StorageFile。
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈