Search.../

listFolders( )

Gets a list of folders from the Media Manager by parentFolderId (or root).

Description

The listFolders() function returns a Promise that resolves to information about the folders in the folder.

To get a list of folders within a specific folder in the Media Manager, pass the folder's ID in the parentFolderId parameter. If no folder is specified, the listFolders() function returns the list of folders in the root folder of the Media Manager.

Note: This function's parameters are positional, and must be specified in the sequence shown in the syntax below. When specifying a parameter, use null as a placeholder for any unspecified parameters. For example, to specify parentFolderId only, call listFolders(filters, null, null). For example, to specify sorting only, call listFolders(null, sorting, null).

Syntax

function listFolders([filters: FolderFilterOptions], [sorting: SortingOptions], [paging: PagingOptions]): FolderInfo

listFolders Parameters

NAME
TYPE
DESCRIPTION
filters
Optional
FolderFilterOptions

Folder filter options.

sorting
Optional
SortingOptions

Sorting options.

paging
Optional
PagingOptions

Paging options.

Returns

Fulfilled - Information about the folders.

Return Type:

Promise<Array<FolderInfo>>
NAME
TYPE
DESCRIPTION
folderId
string

ID of the folder. Internal name (unique identifier) which is generated when a folder is created by the Media Manager. Use this ID when calling the listFiles(), and listFolders() functions.

folderName
string

Name of the folder.

parentFolderId
string

ID of the folder's parent folder. Use this ID when calling the listFiles(), and listFolders() functions.

_createdDate
Date

Date the folder was created.

_updatedDate
Date

Date the folder was updated.

Was this helpful?

List folders in a specified folder

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4const filters = {
5 parentFolderId: "8a3be85ea03e4b8b82f2f9c989557c3d"
6};
7
8export const myListFoldersFunction = webMethod(Permissions.Anyone, () => {
9 return mediaManager.listFolders(filters, null, null)
10 .then((myFolders) => {
11 const folderName = myFolders[0].folderName;
12 const updatedDate = myFolders[1]._updatedDate;
13 return myFolders;
14 })
15 .catch((error) => {
16 console.error(error);
17 });
18});
19
20/* Returns a promise that resolves to:
21 * [{
22 * "folderId": "1bf317e889264736b5acb367415fad8e",
23 * "folderName": "greatfolder1",
24 * "parentFolderId": "8a3be85ea03e4b8b82f2f9c989557c3d",
25 * "_createdDate": "Sun December 4 2020 14:56:15 GMT+0300",
26 * "_updatedDate": "Wed May 12 2021 14:56:15 GMT+0300"
27 * },
28 * {
29 * "folderId": "2fj678p889264736b5acb367415fad5g",
30 * "folderName": "greatfolder2",
31 * "parentFolderId": "8a3be85ea03e4b8b82f2f9c989557c3d",
32 * "_createdDate": "Sun December 4 2020 14:56:15 GMT+0300",
33 * "_updatedDate": "Wed May 12 2021 14:56:15 GMT+0300"
34 * }]
35 */
List folders in the root folder

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4export const myListFoldersFunction = webMethod(Permissions.Anyone, () => {
5 return mediaManager.listFolders()
6 .then((myFolders) => {
7 const folderName = myFolders[0].folderName;
8 const updatedDate = myFolders[1]._updatedDate;
9 return myFolders;
10 })
11 .catch((error) => {
12 console.error(error);
13 });
14});
15
16/* Returns a promise that resolves to:
17 * [{
18 * "folderId": "4nm317e889264736b5acb367415fad6b",
19 * "folderName": "folder1",
20 * "parentFolderId": "media-root",
21 * "_createdDate": "Mon August 5 2019 14:56:15 GMT+0300",
22 * "_updatedDate": "Tues May 12 2021 07:28:12 GMT+0300"
23 * },
24 * {
25 * "folderId": "2t214e889264736b5acb367415fadgc",
26 * "folderName": "folder2",
27 * "parentFolderId": "media-root",
28 * "_createdDate": "Sun December 16 2018 12:22:22 GMT+0300",
29 * "_updatedDate": "Wed June 11 2020 09:34:33 GMT+0300"
30 * }]
31 */
Filter, sort, and paginate a list of folders

In this example we list folders in a specified folder, and sort them in ascending alphabetical order according to the folder name. We skip the first folder in the list and limit the result to the next 2 folders in the list.

Copy Code
1
2import { Permissions, webMethod } from 'wix-web-module';
3import { mediaManager } from 'wix-media-backend';
4
5const filters = {
6 parentFolderId: "8292670cf5434db787bdd9715b46b989"
7};
8
9const sorting = {
10 order: "asc",
11 field: "folderName"
12};
13
14const paging = {
15 limit: 2,
16 skip: 1
17};
18
19export const myListFoldersFunction = webMethod(Permissions.Anyone, () => {
20 return mediaManager.listFolders(filters, sorting, paging)
21 .then((myFolders) => {
22 const folderName = myFolders[0].folderName;
23 const updatedDate = myFolders[1]._updatedDate;
24 return myFolders;
25 })
26 .catch((error) => {
27 console.error(error);
28 });
29});
30
31/* Returns a promise that resolves to:
32 * [{
33 * "folderId": "1bf317e889264736b5acb367415fad8e",
34 * "folderName": "pictures",
35 * "parentFolderId": "8292670cf5434db787bdd9715b46b989",
36 * "_createdDate": "Sat July 4 2017 10:28:12 GMT+0300",
37 * "_updatedDate": "Wed September 17 2020 09:06:15 GMT+0300"
38 * },
39 * {
40 * "folderId": "2t214e889264736b5acb367415fadgc",
41 * "folderName": "videos",
42 * "parentFolderId": "8292670cf5434db787bdd9715b46b989",
43 * "_createdDate": "Sun December 16 2018 12:22:22 GMT+0300",
44 * "_updatedDate": "Wed June 11 2020 09:34:33 GMT+0300"
45 * }]
46 */
47