How can I delete files older than N months?
To delete a filtered range of files, you must write a script to list the files, filter them, and batch-delete them.
Instructions
- Fetch every file for a folder using the ListFolder operation.
- You may need to call this operation multiple times for large folders, as results may be paginated.
- Filter the files you want to delete using a script.
- For example: you can inspect the
lastModified
field for each file to determine its age, and then decide whether to delete the file or keep it based on this value.
- For example: you can inspect the
- Call the DeleteFileBatch operation in batches of 1000 for the files from step (2).
- This is an asynchronous job: you can check each request's status using the GetJob operation.