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.IsOfType、および StorageFolder.IsOfType メソッドによって返されます。

IsOfType メソッドは、ファイルまたはフォルダーにできる IStorageItem インスタンスを返すメソッドの結果を処理する場合に便利です。 たとえば、 GetItemAsync メソッドと GetItemsAsync メソッドは IStorageItem インスタンスを返します。 返されたアイテムを操作するには、IStorageItem インターフェイスの IsOfType メソッドを呼び出して、各項目がファイルかフォルダーかを判断します。 次に、アイテムを StorageFolder または StorageFile にキャストします。

適用対象