StorageItemTypes Enum

Definisi

Menjelaskan apakah item yang mengimplementasikan antarmuka IStorageItem adalah file atau folder.

Enumerasi ini mendukung kombinasi bitwise dari nilai yang termasuk di dalamnya.

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
Warisan
StorageItemTypes
Atribut

Persyaratan Windows

Rangkaian perangkat
Windows 10 (diperkenalkan dalam 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)

Bidang

File 1

File yang direpresentasikan sebagai instans StorageFile .

Folder 2

Folder yang direpresentasikan sebagai instans StorageFolder .

None 0

Item penyimpanan yang bukan file atau folder.

Contoh

Contoh berikut menunjukkan cara mendapatkan file dan subfolder di folder saat ini dengan memanggil metode GetItemsAsync(). Kemudian contoh berulang pada setiap IStorageItem dan memanggil metode IStorageItem.IsOfType untuk menentukan apakah setiap item adalah file atau folder.

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);
}

Keterangan

Nilai dari enumerasi ini dikembalikan oleh metode IStorageItem.IsOfType, StorageFile.IsOfType, dan StorageFolder.IsOfType .

Metode IsOfType berguna untuk memproses hasil dari metode yang mengembalikan instans IStorageItem yang dapat berupa file atau folder. Misalnya, metode GetItemAsync dan GetItemsAsync mengembalikan instans IStorageItem . Untuk bekerja dengan item yang dikembalikan, panggil metode IsOfType antarmuka IStorageItem untuk menentukan apakah setiap item adalah file atau folder. Kemudian transmisikan item ke StorageFolder atau StorageFile.

Berlaku untuk