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

適用於