> 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: bulkDeleteFiles(fileIds: Array, options: BulkDeleteFilesOptions) # Method package: wixMediaV2 # Method menu location: wixMediaV2 --> files --> bulkDeleteFiles # Method Link: https://dev.wix.com/docs/velo/apis/wix-media-v2/files/bulk-delete-files.md # Method Description: Deletes the specified files from the Media Manager.
The deleted files are moved to the Media Manager's trash bin (`TRASH-ROOT` folder) unless permanently deleted. To permanently delete files, specify the `permanent` parameter with the value `true`. Permanently deleting files isn't reversible, so make sure that these files aren't being used in a site or in any other way as the files will no longer be accessible. Note the following: * The specified files can be from different folders. * Moving multiple files at once is an asynchronous action, and may take time for the changes to appear in the Media Manager. * Attempting to delete files that are already in the trash bin doesn't result in an error. * If a site contains deleted media files, the deleted media files still appear on the site as the files are still in the Media Manager (in the trash bin). * You can use Bulk Restore Files From Trash Bin to restore files from the Media Manager's trash bin. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Bulk delete files (dashboard page code) ```javascript import { files } from 'wix-media.v2'; /* Sample fileIds value: * [ * 'w8ide0_v12i2pi4549locqdfeb5yy5b8iyh39az.pdf', * 'w8ide0_ye3x8yyf5izwe01ovn682pa76bzrrcyt.pdf' * ] * * Sample options value: * { * permanent: true * } */ async function myBulkDeleteFilesFunction(fileIds, options) { try { await files.bulkDeleteFiles(fileIds, options); console.log('Permanently deleted files.'); return; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to void */ ``` ## Bulk delete files (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; /* Sample fileIds value: * [ * 'w8ide0_v12i2pi4549locqdfeb5yy5b8iyh39az.pdf', * 'w8ide0_ye3x8yyf5izwe01ovn682pa76bzrrcyt.pdf' * ] * * Sample options value: * { * permanent: true * } */ export const myBulkDeleteFilesFunction = webMethod(Permissions.Anyone, async (fileIds, options) => { try { const elevatedBulkDeleteFiles = elevate(files.bulkDeleteFiles); await elevatedBulkDeleteFiles(fileIds, options); console.log('Permanently deleted files.'); return; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to void */ ``` ## Bulk delete all files found in a chosen folder ```javascript /******************************************* * Backend code - bulk-delete-files.web.js * ******************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-business-tools.v2'; import { elevate } from 'wix-auth'; export const deleteFiles = webMethod(Permissions.Anyone, async (fileIds, options) => { try { const elevatedBulkDeleteFiles = elevate(files.bulkDeleteFiles); await elevatedBulkDeleteFiles(fileIds, options); console.log(`Permanently deleted files with ids: ${fileIds.toString()}.`); return true; } catch (error) { console.error(error); } }); export const searchFileIds = webMethod(Permissions.Anyone, async (parentFolderId) => { try { const options = { parentFolder: parentFolderId }; const elevatedSearchFiles = elevate(files.searchFiles); const returnedFiles = await elevatedSearchFiles(options); const fileIds = returnedFiles.map((file) => { return file._id; }); return fileIds; } catch (error) { console.error(error); } }); /************* * Page code * ************/ import { deleteFiles, searchFileIds } from 'backend/bulk-delete-files.web'; $w.onReady(() => { $w('#delete').onClick(async () => { const isDeletePermanently = $w('#deletePermanently').checked; const options = { permanent: isDeletePermanently }; const parentFolder = $w('#parentFolder').value; const fileIds = await searchFileIds(parentFolder); await deleteFiles(fileIds, options); $w('#successMessage').show(); }); }); ``` ---