Skip to main content
StorageFolder.GetFoldersAsync() | getFoldersAsync() method

Gets the subfolders in the current folder.

Syntax


storageFolder.getFoldersAsync().done( /* Your success and error handlers */ );

public IAsyncOperation<IReadOnlyList> GetFoldersAsync()

Public Function GetFoldersAsync() As IAsyncOperation(Of IReadOnlyList)

public:
IAsyncOperation<IVectorView>^ GetFoldersAsync()

Parameters

This method has no parameters.

Return value

Type: IAsyncOperation<IVectorView>

When this method completes successfully, it returns a list of the subfolders in the current folder. The list is of type IReadOnlyList< StorageFolder>. Each folder in the list is represented by a StorageFolder object.

Exceptions

ExceptionCondition
System.UnauthorizedAccessException

You don't have permission to access the contents of the current folder.

Remarks

This query is a shallow query that returns only subfolders in the current folder. For a list of methods that identifies shallow queries and deep queries, see the Remarks in the topic GetFoldersAsync.

To specify additional query options, call the CreateFolderQueryWithOptions method.

To get items that are files or folders, call the GetItemsAsync method.

Examples

The following example shows how to get the subfolders in the current folder by calling the GetFoldersAsync() method.


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 subfolders in the current folder.
            IReadOnlyList <StorageFolder> subfolders =
                     await appFolder.GetFoldersAsync();

            // Iterate over the results and print the list of folders
            // and files to the Visual Studio Output window.
            foreach (StorageFolder folder in subfolders)
            {
                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);
            }

// Get the app's installation folder.
var appFolder = Windows.ApplicationModel.Package.current.installedLocation;

// Get the subfolders in the current folder.
var subfoldersPromise = appFolder.getFoldersAsync();
subfoldersPromise.done(function getFoldersSuccess(subfolders) {

    // Iterate over the results and print the list of folders
    // and files to the Visual Studio Output window.
    subfolders.forEach(function forEachSubfolder(folder) {
        console.log(folder.name);

        // To iterate over the files in each folder,
        // uncomment the following lines.
        // var getFilesPromise = folder.getFilesAsync();
        // getFilesPromise.done(function getFilesSuccess(files) {
        //     console.log(folder.name);
        //     files.forEach(function forEachFile(file) {
        //         console.log(".", file.name);
        //     });
        // });
    });
});

 // Get installation folder
 StorageFolder^ appFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

 // Get the subfolders in the current folder.
 create_task(appFolder->GetFoldersAsync()).then([=](IVectorView<StorageFolder^>^ itemsInFolder) {
  //Iterate over the results and print the list of folders
  // 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());
  }
 });

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

See also

StorageFolder
GetFoldersAsync(CommonFolderQuery, UInt32, UInt32)
GetFoldersAsync(CommonFolderQuery)
GetItemsAsync