StorageFolder.CreateItemQuery 메서드

정의

현재 폴더의 파일 및 하위 폴더가 포함된 쿼리 결과 개체를 가져옵니다.

public:
 virtual StorageItemQueryResult ^ CreateItemQuery() = CreateItemQuery;
StorageItemQueryResult CreateItemQuery();
public StorageItemQueryResult CreateItemQuery();
function createItemQuery()
Public Function CreateItemQuery () As StorageItemQueryResult

반환

쿼리 결과 개체입니다. 쿼리 결과의 GetItemsAsync 메서드를 호출하여 현재 폴더의 파일 및 하위 폴더를 가져옵니다. 이 메서드는 IReadOnlyList<IStorageItem> 형식의 목록을 반환합니다. 각 파일 또는 폴더는 IStorageItem 형식의 항목으로 표시됩니다.

반환된 항목을 사용하려면 IStorageItem 인터페이스의 IsOfType 메서드를 호출하여 각 항목이 파일인지 폴더인지 확인합니다. 그런 다음, 항목을 StorageFolder 또는 StorageFile으로 캐스팅합니다.

구현

예외

현재 폴더의 내용에 액세스할 수 있는 권한이 없습니다.

예제

다음 예제에서는 CreateItemQuery() 메서드를 호출하여 현재 폴더의 파일 및 하위 폴더를 가져오는 방법을 보여 줍니다.

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

// Get the app's installation folder.
StorageFolder appFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

// Get the items in the current folder.
StorageItemQueryResult itemsInFolder = appFolder.CreateItemQuery();

// Iterate over the results and print the list of items
// to the Visual Studio Output window.
foreach (IStorageItem item in await itemsInFolder.GetItemsAsync())
{
    if(item.IsOfType(StorageItemTypes.Folder))
        Debug.WriteLine("Folder: " + item.Name);
    else
        Debug.WriteLine("File: " + item.Name + ", " + item.DateCreated);
}
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    // Get the app's installation folder.
    Windows::Storage::StorageFolder appFolder{ Windows::ApplicationModel::Package::Current().InstalledLocation() };

    Windows::Storage::Search::StorageItemQueryResult results{ appFolder.CreateItemQuery() };

    // Get the items in the current folder.
    Windows::Foundation::Collections::IVectorView<Windows::Storage::IStorageItem> itemsInFolder{
        co_await results.GetItemsAsync() };

    // Iterate over the results, and print the list of items to the Visual Studio output window.
    for (IStorageItem const& itemInFolder : itemsInFolder)
    {
        std::wstringstream stringstream;

        if (itemInFolder.IsOfType(Windows::Storage::StorageItemTypes::File))
        {
            stringstream << L"File: ";
        }
        else
        {
            stringstream << L"Folder: ";
        }

        stringstream << itemInFolder.Name().c_str() << std::endl;
        ::OutputDebugString(stringstream.str().c_str());
    }
}
// Get the app's installation folder
StorageFolder^ appFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

StorageItemQueryResult^ results = appFolder->CreateItemQuery();

// Get the items in the current folder; 
create_task(results->GetItemsAsync()).then([=](IVectorView<IStorageItem^>^ itemsInFolder) {

 //Iterate over the results and print the list of items
    // to the visual studio output window
    for (auto it = itemsInFolder->First(); it->HasCurrent; it->MoveNext())
    {
        IStorageItem^ item = it->Current;
        if (item->IsOfType(StorageItemTypes::File))
        {
            String^ output = "File: " + item->Name + "\n";
            OutputDebugString(output->Begin());
        }
        else
        {
            String^ output = "Folder: " + item->Name + "\n";
            OutputDebugString(output->Begin());
        }        
    }
});

설명

이 쿼리는 현재 폴더의 항목만 반환하는 단순 쿼리입니다. 단순 쿼리 및 심층 쿼리를 식별하는 메서드 목록은 GetItemsAsync 항목의 설명을 참조하세요.

GetItemsAsync 메서드 중 하나를 호출하여 현재 폴더의 항목 목록을 비동기적으로 가져올 수도 있습니다.

추가 쿼리 옵션을 지정하려면 CreateItemQueryWithOptions 메서드를 호출합니다 .

적용 대상