OneDrive File Issues

How to Automatically Delete OneDrive Files Except Selected Folders

Adam DavisAdam Davis Nov 2, 2026 868 views

Question details

The user wants to set up a rule to automatically delete files from their OneDrive storage while keeping files located in specific excluded folders safe from deletion.

How to Automatically Delete OneDrive Files Except Selected Folders
Product
Microsoft OneDrive
Device & OS
not provided
Scenario
Managing limited cloud storage space by automating the cleanup of old or unnecessary files without accidentally deleting important directories.
Observed behavior
OneDrive does not offer a native, built-in setting to automatically delete files while honoring folder exclusion rules.
Before you start

Ensure you have access to Microsoft Power Automate with the same Microsoft account linked to your OneDrive, and create a backup of your files before testing any automated deletion rules.

Solution 1Recommended

Use Microsoft Power Automate to Filter and Delete Files

Since OneDrive lacks a built-in exclusion feature for deletion, you can create a custom Power Automate flow to scan your files, check them against your excluded folder names, and delete the rest.

Power Automate is Microsoft's workflow automation tool. By building a scheduled cloud flow, you can command OneDrive to list all its files, verify the folder path of each file, and only execute the delete command if the file is not in your safe list.

1
Create a Scheduled Cloud Flow

Log into Microsoft Power Automate online. Click on 'Create' from the left sidebar and select 'Scheduled cloud flow'. Set how frequently you want the cleanup process to run (e.g., every week).

2
List OneDrive Files

Add a new step and search for the OneDrive connector. Select the 'List files in folder' action and specify the root directory or specific target folder you want to clean up.

3
Add a Condition for Excluded Folders

Insert a 'Condition' control into your flow. Set the condition to check if the file's 'Path' or 'Folder' property 'does not contain' the name of the folder you want to keep safe.

4
Configure the Deletion Action

In the 'If yes' branch of your condition, add the OneDrive 'Delete file' action. Use the dynamic 'Id' content from the earlier step so the flow knows exactly which file to remove.

5
Test the Flow

Save your flow and click 'Test' in the upper right corner. Run the test manually on a folder containing dummy files to ensure it only deletes the intended items.

Use Microsoft Power Automate to Filter and Delete Files
Community Templates Available: If you are unfamiliar with building flows from scratch, you can browse the Microsoft Power Automate Community forums for pre-built templates related to deleting OneDrive files older than 60 days or managing folder retentions.
Free Microsoft Office alternative

Simplify Document Management with WPS Office

While setting up complex automation flows for Microsoft OneDrive can be time-consuming, WPS Office offers a straightforward, lightweight, and highly compatible alternative for your daily document and cloud storage needs. Enjoy seamless file management without the heavy subscriptions.

  1. 1. Download WPS Office: Visit the official WPS Office website and download the free installation package for your operating system.
  2. 2. Install the Software: Run the installer and follow the simple on-screen instructions to set up the software on your device.
  3. 3. Access Cloud Documents: Open WPS Office and navigate to the Cloud tab to easily manage, edit, and organize your files.
Free and lightweight Office suite with an intuitive, user-friendly interface.Highly compatible with Microsoft Office formats, including DOCX, XLSX, and PPTX.Built-in cloud integration for effortless document saving, syncing, and backup.No complex scripts required for organizing your daily workflow.
microsoft office alternative - wps office

Frequently Asked Questions

Does OneDrive have a built-in auto-delete feature?

No, Microsoft OneDrive does not currently feature a native setting to automatically delete files or exclude specific folders on a schedule. You must rely on third-party scripts or Microsoft Power Automate to achieve this.

Can I automatically delete files older than a certain date?

Yes, by adding a time-based condition to your Power Automate flow. You can use an expression to check the file's 'Last modified' timestamp against a date (like 30 or 60 days ago) before triggering the delete action.

Where do deleted OneDrive files go when removed by a flow?

Files deleted by a standard Power Automate OneDrive action are generally sent to the OneDrive Recycle Bin. They remain there for up to 30 days (or 93 days for work/school accounts) before being permanently erased, allowing you to recover accidental deletions.

Can I apply this flow to multiple excluded folders?

Yes, you can add multiple criteria to the 'Condition' block in Power Automate by using the 'AND' logic rule. Simply add a new row for each folder path you want to exclude from the deletion process.