StorageFolder.CreateFileQueryWithOptions(QueryOptions) 메서드

정의

현재 폴더의 파일을 포함하고 필요에 따라 현재 폴더의 하위 폴더에 있는 쿼리 결과 개체를 가져옵니다. 결과는 지정된 QueryOptions를 기반으로 합니다.

public:
 virtual StorageFileQueryResult ^ CreateFileQueryWithOptions(QueryOptions ^ queryOptions) = CreateFileQueryWithOptions;
StorageFileQueryResult CreateFileQueryWithOptions(QueryOptions const& queryOptions);
public StorageFileQueryResult CreateFileQueryWithOptions(QueryOptions queryOptions);
function createFileQueryWithOptions(queryOptions)
Public Function CreateFileQueryWithOptions (queryOptions As QueryOptions) As StorageFileQueryResult

매개 변수

queryOptions
QueryOptions

쿼리에 적용되는 조건입니다.

반환

현재 폴더의 파일을 포함하고 필요에 따라 현재 폴더의 하위 폴더에 있는 지정된 QueryOptions에 따라 필터링 및 정렬되는 쿼리 결과 개체입니다. 쿼리 결과의 GetFilesAsync 메서드를 호출하여 queryOptions에 지정된 대로 정렬된 파일의 플랫 목록을 가져옵니다. 이 메서드는 IReadOnlyList<StorageFile 형식의 목록을 반환합니다>. 각 파일은 StorageFile 형식의 항목으로 표시됩니다.

구현

예외

라이브러리 폴더가 아닌 폴더에 대한 CommonFileQuery 열거형에서 DefaultQuery 이외의 값을 지정했습니다. 쿼리 값을 확인 합니다.

예제

다음 예제에서는 메서드를 호출 CreateFileQueryWithOptions(QueryOptions) 하여 날짜별로 정렬된 사용자의 Pictures 폴더 및 하위 폴더에 JPG 파일을 가져오는 방법을 보여 있습니다. 이 쿼리는 폴더가 라이브러리 폴더이고 CommonFileQuery 열거형의 DefaultQuery 이외의 값이 지정되기 때문에 심층 쿼리입니다.

다음 예제를 실행하기 전에 앱 매니페스트 파일에서 그림 라이브러리 기능을 사용하도록 설정합니다.

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

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

// Set options for file type and sort order.
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".jpg");
QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByDate, fileTypeFilter);

// Get the JPG files in the user's Pictures folder
// and its subfolders and sort them by date.
StorageFileQueryResult results = picturesFolder.CreateFileQueryWithOptions(queryOptions);

// Iterate over the results and print the list of files
// to the Visual Studio Output window.
IReadOnlyList<StorageFile> sortedFiles = await results.GetFilesAsync();
foreach (StorageFile item in sortedFiles)
{
    Debug.WriteLine(item.Name + ", " + item.DateCreated);
}
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() };

    // Set options for file type and sort order.
    Windows::Storage::Search::QueryOptions queryOptions{ Windows::Storage::Search::CommonFileQuery::OrderByDate, { L".png" } };

    // Get the png files in the user's Pictures folder and its subfolders, sorted by date.
    Windows::Storage::Search::StorageFileQueryResult results{ picturesFolder.CreateFileQueryWithOptions(queryOptions) };

    Windows::Foundation::Collections::IVectorView<Windows::Storage::StorageFile> filesInFolder{
        co_await results.GetFilesAsync() };

    // Iterate over the results, and print the list of files to the Visual Studio output window.
    for (StorageFile const& fileInFolder : filesInFolder)
    {
        std::wstring output{ fileInFolder.Name() };
        ::OutputDebugString(output.c_str());
    }
}
//Get the users's pictures folder
//Enable the corresponding capability in the app manifest file
StorageFolder^ picturesFolder = KnownFolders::PicturesLibrary;

//Set options for file type and sort order
Platform::Collections::Vector<String^>^ fileTypeFilter = ref new Platform::Collections::Vector<String^>();
fileTypeFilter->Append(".jpg");
QueryOptions^ queryOptions = ref new QueryOptions(Windows::Storage::Search::CommonFileQuery::OrderByDate, fileTypeFilter);

//Get the JPG files in the user's pictures folder 
//and its subfolders and sort them by date
StorageFileQueryResult^ results = picturesFolder->CreateFileQueryWithOptions(queryOptions);

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

설명

다음 경우 이 쿼리는 현재 폴더의 파일만 반환하는 단순 쿼리입니다.

  • 다음 옵션 중 어느 것도 지정되지 않은 경우 이 메서드의 기본 동작입니다. 또는:
  • QueryOptions 개체를 인스턴스화할 때 DefaultQueryCommonFileQuery 값으로 지정합니다. 또는:
  • QueryOptions 개체의 FolderDepth 속성 값으로 Shallow을 지정합니다.

다음 경우 이 쿼리는 현재 폴더와 하위 폴더의 파일을 반환하는 심층 쿼리입니다.

CommonFileQuery 열거형의 일부 값은 라이브러리 폴더(예: 사진 라이브러리) 또는 홈 그룹 폴더에서만 사용할 수 있습니다. 위에서 설명한 ArgumentException 의 표현에도 불구하고 OrderByNameOrderBySearchRank 옵션( DefaultQuery 옵션 외에도)을 라이브러리 폴더가 아닌 폴더와 함께 사용할 수 있습니다.

단순 쿼리 및 심층 쿼리를 식별하는 메서드 목록은 GetFilesAsync 항목의 설명을 참조하세요.

지정하려는 QueryOptions 를 현재 폴더에 사용할 수 있는지 확인하려면 폴더의 AreQueryOptionsSupported 메서드를 호출합니다. 특정 CommonFileQuery 를 사용할 수 있는지 확인하려면 폴더의 IsCommonFileQuerySupported 메서드를 호출합니다.

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

QueryOptions 개체를 구성하지 않고 현재 폴더에 파일이 포함된 쿼리 결과 개체를 얻으려면 CreateFileQuery 메서드 중 하나를 호출합니다.

파일 또는 폴더인 항목을 얻으려면 CreateItemQueryWithOptions 메서드를 호출합니다 .

참고

Windows Server 2012 인덱서 구성 요소는 기본적으로 설치되지 않으므로 일부 QueryOptions를 사용하려면 인덱서 구성 요소를 설치해야 합니다.

적용 대상

추가 정보