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 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應