StorageFolder.GetItemsAsync 메서드

정의

오버로드

GetItemsAsync()

현재 폴더의 파일 및 하위 폴더를 가져옵니다.

GetItemsAsync(UInt32, UInt32)

현재 폴더의 모든 파일 및 하위 폴더 목록에서 인덱스 기반 파일 및 폴더 범위를 가져옵니다.

GetItemsAsync()

현재 폴더의 파일 및 하위 폴더를 가져옵니다.

public:
 virtual IAsyncOperation<IVectorView<IStorageItem ^> ^> ^ GetItemsAsync() = GetItemsAsync;
/// [Windows.Foundation.Metadata.Overload("GetItemsAsyncOverloadDefaultStartAndCount")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<IVectorView<IStorageItem>> GetItemsAsync();
[Windows.Foundation.Metadata.Overload("GetItemsAsyncOverloadDefaultStartAndCount")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<IReadOnlyList<IStorageItem>> GetItemsAsync();
function getItemsAsync()
Public Function GetItemsAsync () As IAsyncOperation(Of IReadOnlyList(Of IStorageItem))

반환

이 메서드가 성공적으로 완료되면 현재 폴더의 파일 및 폴더 목록을 반환합니다. 목록은 IReadOnlyList<IStorageItem> 형식입니다. 목록의 각 항목은 IStorageItem 개체로 표시됩니다.

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

구현

특성

예외

현재 폴더의 내용에 액세스할 수 있는 권한이 없습니다. 자세한 내용은 파일 액세스 권한을 참조하세요.

예제

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

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);
}
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    // Get the app's installation folder.
    Windows::Storage::StorageFolder appFolder{ Windows::ApplicationModel::Package::Current().InstalledLocation() };

    // Get the items in the current folder.
    Windows::Foundation::Collections::IVectorView<Windows::Storage::IStorageItem> itemsInFolder{
        co_await appFolder.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 apps installation folder
StorageFolder^ appFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

// Get the items in the current folder; 
create_task(appFolder->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());
  }
 }
});

설명

다음 표에서는 파일 및 폴더 목록을 가져오는 StorageFolder 클래스의 메서드를 나열합니다. 테이블은 현재 폴더의 항목만 반환하는 단순 쿼리와 현재 폴더 및 하위 폴더의 항목을 반환하는 심층 쿼리를 식별합니다.

라이브러리 폴더가 아닌 폴더에서 심층 쿼리 결과를 얻으려면 CreateItemQueryWithOptions(QueryOptions) 메서드를 호출하고 DeepQueryOptions 개체의 FolderDepth 속성 값으로 지정합니다.

메서드 현재 폴더의 항목만 반환하는 단순 쿼리 만들기 현재 폴더 및 하위 폴더에서 항목을 반환하는 심층 쿼리 만들기
GetItemsAsync() 이 메서드의 기본 동작입니다. 해당 없음
GetItemsAsync(UInt32, UInt32) 이 메서드의 기본 동작입니다. 해당 없음
CreateItemQuery() 이 메서드의 기본 동작입니다. 해당 없음
CreateItemQueryWithOptions(QueryOptions) 다음 옵션 중 어느 것도 지정되지 않은 경우 이 메서드의 기본 동작입니다.
-또는-
QueryOptions 개체를 인스턴스화할 때 DefaultQueryCommonFileQuery 또는 CommonFolderQuery 값으로 지정합니다.
-또는-
ShallowQueryOptions 개체의 FolderDepth 속성 값으로 지정합니다.
라이브러리 폴더의 경우 QueryOptions 개체를 인스턴스화할 때 DefaultQuery 이외의 값을 CommonFileQuery 또는 CommonFolderQuery 값으로 지정합니다.
-또는-
모든 폴더에 대해 QueryOptionsFolderDepth 속성 값으로 Deep을 지정합니다.

파일만 얻으려면 GetFilesAsync 메서드를 호출합니다. 폴더만 얻으려면 GetFoldersAsync 메서드를 호출합니다.

추가 정보

적용 대상

GetItemsAsync(UInt32, UInt32)

현재 폴더의 모든 파일 및 하위 폴더 목록에서 인덱스 기반 파일 및 폴더 범위를 가져옵니다.

public:
 virtual IAsyncOperation<IVectorView<IStorageItem ^> ^> ^ GetItemsAsync(unsigned int startIndex, unsigned int maxItemsToRetrieve) = GetItemsAsync;
/// [Windows.Foundation.Metadata.Overload("GetItemsAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<IVectorView<IStorageItem>> GetItemsAsync(uint32_t const& startIndex, uint32_t const& maxItemsToRetrieve);
[Windows.Foundation.Metadata.Overload("GetItemsAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<IReadOnlyList<IStorageItem>> GetItemsAsync(uint startIndex, uint maxItemsToRetrieve);
function getItemsAsync(startIndex, maxItemsToRetrieve)
Public Function GetItemsAsync (startIndex As UInteger, maxItemsToRetrieve As UInteger) As IAsyncOperation(Of IReadOnlyList(Of IStorageItem))

매개 변수

startIndex
UInt32

unsigned int

uint32_t

가져올 범위에서 첫 번째 항목의 인덱스(0부터 시작)입니다.

maxItemsToRetrieve
UInt32

unsigned int

uint32_t

가져올 최대 항목 수입니다.

반환

이 메서드가 성공적으로 완료되면 현재 폴더의 파일 및 하위 폴더 목록을 반환합니다. 목록은 IReadOnlyList<IStorageItem> 형식입니다. 목록의 각 항목은 IStorageItem 개체로 표시됩니다.

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

구현

M:Windows.Storage.Search.IStorageFolderQueryOperations.GetItemsAsync(System.UInt32,System.UInt32) M:Windows.Storage.Search.IStorageFolderQueryOperations.GetItemsAsync(unsigned int,unsigned int) M:Windows.Storage.Search.IStorageFolderQueryOperations.GetItemsAsync(uint32_t,uint32_t)
특성

예외

현재 폴더의 내용에 액세스할 수 있는 권한이 없습니다. 자세한 내용은 파일 액세스 권한을 참조하세요.

추가 정보

적용 대상