> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: searchFolders(options: SearchFoldersOptions) # Method package: wixMediaV2 # Method menu location: wixMediaV2 --> folders --> searchFolders # Method Link: https://dev.wix.com/docs/velo/apis/wix-media-v2/folders/search-folders.md # Method Description: Searches the Media Manager and returns a list of folders that match the terms specified in the parameters.
If no parameters are specified, the method returns all folders in the `MEDIA_ROOT` folder. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Search folders (dashboard page code) ```javascript import { folders } from 'wix-media.v2'; async function mySearchFoldersFunction() { try { const foldersFound = await folders.searchFolders(); console.log("Folders found in search:", foldersFound); return foldersFound; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "folders": [ * { * "_createdDate": "2023-08-14T07:41:19.000Z", * "_id": "103601562ec94214bee61f470b403dd5", * "_updatedDate": "2023-08-21T11:09:08.000Z", * "displayName": "Pictures", * "parentFolderId": "media-root", * "state": "OK" * }, * { * "_createdDate": "2023-08-21T05:34:03.000Z", * "_id": "302fc049d70c41dea33fa4a27ab481ba", * "_updatedDate": "2023-08-21T05:34:03.000Z", * "displayName": "Videos", * "parentFolderId": "media-root", * "state": "OK" * } * ], * "nextCursor": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ## Search folders (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { folders } from 'wix-media.v2'; import { elevate } from 'wix-auth'; export const mySearchFoldersFunction = webMethod(Permissions.Anyone, async () => { try { const elevatedSearchFolders = elevate(folders.searchFolders); const foldersFound = await elevatedSearchFolders(); console.log("Folders found in search:", foldersFound); return foldersFound; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "folders": [ * { * "_createdDate": "2023-08-14T07:41:19.000Z", * "_id": "103601562ec94214bee61f470b403dd5", * "_updatedDate": "2023-08-21T11:09:08.000Z", * "displayName": "Pictures", * "parentFolderId": "media-root", * "state": "OK" * }, * { * "_createdDate": "2023-08-21T05:34:03.000Z", * "_id": "302fc049d70c41dea33fa4a27ab481ba", * "_updatedDate": "2023-08-21T05:34:03.000Z", * "displayName": "Videos", * "parentFolderId": "media-root", * "state": "OK" * } * ], * "nextCursor": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ## Search for 2 folders by key-word, returned alphabetically ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { folders } from 'wix-media.v2'; import { elevate } from 'wix-auth'; /* Sample options value: * { * search: 'mountains', * sort: { * fieldName: 'updatedDate', * order: 'ASC' * }, * paging: { * limit: 2 * } * } */ export const mySearchFoldersFunction = webMethod(Permissions.Anyone, async (options) => { try { const elevatedSearchFolders = elevate(folders.searchFolders); const foldersFound = await elevatedSearchFolders(options); console.log("Folders found in search:", foldersFound); return foldersFound; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "folders": [ * { * "_createdDate": "2023-08-21T09:32:34.000Z", * "_id": "7984b3c5454e4371acbd4f4eedde96bc", * "_updatedDate": "2023-08-21T11:10:51.000Z", * "displayName": "mountains", * "parentFolderId": "103601562ec94214bee61f470b403dd5", * "state": "OK" * }, * { * "_createdDate": "2023-08-24T11:26:26.000Z", * "_id": "742d4a0ee5884b119292d52ed964f14d", * "_updatedDate": "2023-08-24T11:26:26.000Z", * "displayName": "mountain_videos", * "parentFolderId": "302fc049d70c41dea33fa4a27ab481ba", * "state": "OK" * } * ], * "nextCursor": { * "cursors": { * "next": "eyJ0b3RhbCI6IDEsICJvZmZzZXQiOiAyfQ==" * }, * "hasNext": true * } * } */ ``` ## Bulk delete all folders ```javascript /**************************************** * Backend code - delete-folders.web.js * ***************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { folders } from 'wix-media.v2'; import { elevate } from 'wix-auth'; export const deleteFolders = webMethod(Permissions.Anyone, async (folderIds) => { try { const elevatedBulkDeleteFolders = elevate(folders.bulkDeleteFolders); const deletedFolders = await elevatedBulkDeleteFolders(folderIds); console.log('Successfully moved folders to trash.'); return deletedFolders; } catch (error) { console.error(error); } }); export const listFolders = webMethod(Permissions.Anyone, async () => { try { const elevatedListFolders = elevate(folders.listFolders) const foldersList = await elevatedListFolders(); return foldersList; } catch (error) { console.error(error); } }); export const searchFolders = webMethod(Permissions.Anyone, async (options) => { try { const elevatedSearchFolders = elevate(folders.searchFolders) const foldersFound = await elevatedSearchFolders(options); return foldersFound; } catch (error) { console.error(error); } }); /************* * Page code * ************/ import { deleteFolders, listFolders, searchFolders } from 'backend/delete-folders.web'; $w.onReady(async () => { await populateFoldersDropdown(); $w('#bulkDelete').onClick(async () => { const searchOptions = { rootFolder: $w('#foldersDropdown').value}; const foldersToDelete = await searchFolders(searchOptions); const foldersIdsToDelete = foldersToDelete.map((folder) => { return folder._id; }); await deleteFolders(foldersIdsToDelete); console.log(`Successfully deleted all folders found in ${$w('#foldersDropdown').label}.`) $w('#bulkDeleteSuccessMsg').show(); }); }); async function populateFoldersDropdown() { const folders = await listFolders(); const dropdownOptions = folders.map((folder) => { return { label: folder.displayName, value: folder._id }; }); $w('#foldersDropdown').options = dropdownOptions; }; ``` ---