StorageFolder.CreateFolderQuery() | createFolderQuery() method

Applies to Windows only

Gets a query result object that contains the subfolders in the current folder.

Syntax


var storageFolderQueryResult = storageFolder.createFolderQuery();

Parameters

This method has no parameters.

Return value

Type: StorageFolderQueryResult

A query result object. Call the GetFoldersAsync method of the query result to get the subfolders in the current folder. This method returns a list of type IReadOnlyList<StorageFolder>. Each file or folder is represented by an item of type StorageFolder.

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.

You can also get a list of subfolders in the current folder asynchronously by calling one of the GetFoldersAsync methods.

To specify additional query options, call the CreateFolderQueryWithOptions method.

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

Examples

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

Before you run the following example, enable the Pictures Library capability in the app manifest file.


// Get the user's Pictures folder.
// Enable the corresponding capability in the app manifest file.
var KnownFolders = Windows.Storage.KnownFolders;
var picturesFolder = KnownFolders.picturesLibrary;

// Get the subfolders in the user's Pictures folder.
var itemsInFolder = picturesFolder.createFolderQuery();

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

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

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

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

Metadata

Windows.winmd

See also

StorageFolder
CreateFolderQuery(CommonFolderQuery)

 

 

Show:
© 2014 Microsoft