StorageFolder.CreateFolderQuery メソッド

定義

オーバーロード

CreateFolderQuery()

現在のフォルダー内のサブフォルダーを含むクエリ結果オブジェクトを取得します。

CreateFolderQuery(CommonFolderQuery)

現在のフォルダー内のサブフォルダーを含むクエリ結果オブジェクトを取得します。 クエリ引数の値が CommonFolderQuery.DefaultQuery 以外の場合は、現在のフォルダーのサブフォルダー内のファイルグループのコンテナーを表す仮想フォルダーの一覧を取得します。 ファイルは、 CommonFolderQuery 列挙体の指定された値に基づいてフォルダーにグループ化されます。

CreateFolderQuery()

現在のフォルダー内のサブフォルダーを含むクエリ結果オブジェクトを取得します。

public:
 virtual StorageFolderQueryResult ^ CreateFolderQuery() = CreateFolderQuery;
/// [Windows.Foundation.Metadata.Overload("CreateFolderQueryOverloadDefault")]
StorageFolderQueryResult CreateFolderQuery();
[Windows.Foundation.Metadata.Overload("CreateFolderQueryOverloadDefault")]
public StorageFolderQueryResult CreateFolderQuery();
function createFolderQuery()
Public Function CreateFolderQuery () As StorageFolderQueryResult

戻り値

クエリ結果オブジェクト。 クエリ結果の GetFoldersAsync メソッドを呼び出して、現在のフォルダー内のサブフォルダーを取得します。 このメソッドは、IReadOnlyList<StorageFolder 型のリストを返します>。 各ファイルまたはフォルダーは、 StorageFolder 型の項目で表されます。

実装

属性

例外

現在のフォルダーの内容にアクセスするためのアクセス許可がありません。

次の例では、 GetFoldersAsync(CommonFolderQuery) オーバーロード メソッドを呼び出して、ユーザーの Pictures フォルダー内のサブフォルダーの内容を取得する方法を示します。 (現在のフォルダーのルートからのファイルは含まれません。

次の例を実行する前に、アプリ マニフェスト ファイルで Pictures Library 機能を有効にします。

using Windows.Storage;
using Windows.Storage.Search;
using System.Threading.Tasks;
using System.Diagnostics; // For writing results to the Output window.

// Get the user's Pictures folder.
// Enable the corresponding capability in the app manifest file.
StorageFolder picturesFolder = KnownFolders.PicturesLibrary;

// Get the files in the subfolders of the
// user's Pictures folder, grouped by month.
StorageFolderQueryResult groupedItems =
    picturesFolder.CreateFolderQuery(CommonFolderQuery.GroupByMonth);

// Iterate over the results and print the list of folders
// and files to the Visual Studio Output window.
foreach (StorageFolder folder in await groupedItems.GetFoldersAsync())
{
    Debug.WriteLine(folder.Name);

// To iterate over the files in each folder,
// uncomment the following lines.
// foreach(StorageFile file in await folder.GetFilesAsync())
//    Debug.WriteLine(" " + file.Name);
}
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    // Get the users's Pictures folder.
    // Enable the Pictures Library capability in the app manifest file.
    Windows::Storage::StorageFolder picturesFolder{ Windows::Storage::KnownFolders::PicturesLibrary() };

    // Get the files in the user's Pictures folder, and group them by month.
    Windows::Storage::Search::StorageFolderQueryResult results{ picturesFolder.CreateFolderQuery(Windows::Storage::Search::CommonFolderQuery::GroupByMonth) };

    Windows::Foundation::Collections::IVectorView<Windows::Storage::StorageFolder> itemsInFolder{
        co_await results.GetFoldersAsync() };

    // Iterate over the results, and print the list of file groups to the Visual Studio output window.
    for (StorageFolder const& itemInFolder : itemsInFolder)
    {
        std::wstring output{ itemInFolder.Name() };
        ::OutputDebugString(output.c_str());
    }
}
// Get user's pictures folder
StorageFolder^ picturesFolder = KnownFolders::PicturesLibrary;

// Get the files in the user's Pictures folder and group them by month
StorageFolderQueryResult^ itemsInFolder = picturesFolder->CreateFolderQuery(CommonFolderQuery::GroupByMonth);

create_task(itemsInFolder->GetFoldersAsync()).then([=](IVectorView<StorageFolder^>^ itemsInFolder) {
 //Iterate over the results and print the list of file groups
 // to the visual studio output window
 for (auto it = itemsInFolder->First(); it->HasCurrent; it->MoveNext())
 {
  StorageFolder^ file = it->Current;
  String^ output = file->Name + "\n";
  OutputDebugString(output->Begin());
 }
});

注釈

このクエリは、現在のフォルダー内のサブフォルダーのみを返すシャロー クエリです。 シャロー クエリとディープ クエリを識別するメソッドの一覧については、 GetFoldersAsync メソッドの「解説」を参照してください。

追加のクエリ オプションを指定するには、 CreateFolderQueryWithOptions メソッドを 呼び出します。

ファイルまたはフォルダーであるアイテムを取得するには、 CreateItemQuery メソッドを呼び出します。

こちらもご覧ください

適用対象

CreateFolderQuery(CommonFolderQuery)

現在のフォルダー内のサブフォルダーを含むクエリ結果オブジェクトを取得します。 クエリ引数の値が CommonFolderQuery.DefaultQuery 以外の場合は、現在のフォルダーのサブフォルダー内のファイルグループのコンテナーを表す仮想フォルダーの一覧を取得します。 ファイルは、 CommonFolderQuery 列挙体の指定された値に基づいてフォルダーにグループ化されます。

public:
 virtual StorageFolderQueryResult ^ CreateFolderQuery(CommonFolderQuery query) = CreateFolderQuery;
/// [Windows.Foundation.Metadata.Overload("CreateFolderQuery")]
StorageFolderQueryResult CreateFolderQuery(CommonFolderQuery const& query);
[Windows.Foundation.Metadata.Overload("CreateFolderQuery")]
public StorageFolderQueryResult CreateFolderQuery(CommonFolderQuery query);
function createFolderQuery(query)
Public Function CreateFolderQuery (query As CommonFolderQuery) As StorageFolderQueryResult

パラメーター

query
CommonFolderQuery

ファイルをフォルダーにグループ化する方法を指定し、クエリが浅いか深いかを決定する列挙値の 1 つ。

戻り値

クエリ結果オブジェクト。 クエリ結果の GetFoldersAsync メソッドを呼び出して、現在のフォルダー内のサブフォルダーを取得します。 クエリ引数の値が CommonFolderQuery.DefaultQuery 以外の値である場合、クエリ結果オブジェクトには、現在のフォルダーのサブフォルダー内のファイルのグループのコンテナーを表す仮想フォルダーの一覧が含まれます。 (現在のフォルダーのファイルは含まれません。ファイルは 、クエリで指定されたとおりにグループ化されます。 リストの種類は IReadOnlyList<StorageFolder です>。 リスト内の各フォルダーは、 StorageFolder オブジェクトによって表されます。

実装

属性

例外

現在のフォルダーの内容にアクセスするためのアクセス許可がありません。

ライブラリ フォルダーではないフォルダーに対して<、xref:Windows.Storage.Search.CommonFolderQuery?text=CommonFolderQuery 列挙から DefaultQuery> 以外の値を指定しました。 クエリの値を確認 します

注釈

CommonFolderQuery は、特定のファイル属性 (アーティストやアルバムなど) に基づいて、サブフォルダーの内容をフォルダーにすばやく簡単にグループ化します。 DefaultQuery オプションの指定の詳細については、「 CreateFileQuery メソッド」ページの「解説 」を 参照してください。

こちらもご覧ください

適用対象