StorageItemTypes 枚举

定义

描述实现 IStorageItem 接口的项是文件还是文件夹。

此枚举支持其成员值的按位组合。

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.IsOfTypeStorageFile.IsOfTypeStorageFolder.IsOfType 方法返回。

IsOfType 方法可用于处理返回可以是文件或文件夹的 IStorageItem 实例的方法的结果。 例如, GetItemAsyncGetItemsAsync 方法返回 IStorageItem 实例。 若要处理返回的项,请调用 IStorageItem 接口的 IsOfType 方法,以确定每个项是文件还是文件夹。 然后将项强制转换为 StorageFolderStorageFile

适用于