How to delete Sharepoint Online Documents in a Document Library using a SQL Query or CSV List

Copper Contributor

I have hundreds of SharePoint Libraries, each which contains a thousands of document folders beginning with "JOB-".


There are probably 100,000+ of these "JOB-" folders. 

Examples are "JOB-1234-9876", or "JOB-2222-1837", etc.


I have a CSV file that contains a list of thousands of specific folders that need to be deleted. The problem is there are 100,000+ folders and maybe 6000 specific ones that need to be deleted. 


I am hoping there is an easy way for me to use the CSV list or paste the specific folders into some kind of deletion tool that can take my folder list and then go delete all the folders and their child records as many have subfolders and files and I need to ensure everything 'inside' each folder is also deleted.  


I use ShareGate to copy the folders to new locations when there are specific business needs that dictate the location must change. However, ShareGate does not provide me with a way to delete the source folders since I have to use a SpreadSheet import process to copy the folders, -- their UI doesn't provide a way to only copy specific folders without using the spreadsheet. 


And once the folders and their contents get copied to the new location via ShareGate, I need to delete the original source. 


Can anyone provide any recommendations or recommend a tool that will allow me to do this. This will be an ongoing need every few weeks to delete very specific folders and their contents. 


Any recommendations or suggestions would be greatly appreciated. 


2 Replies
best response confirmed by ACECORP (Copper Contributor)
Thanks. That looks like it will work. Will work to get that applied to my specific situation and see what happens.
1 best response

Accepted Solutions
best response confirmed by ACECORP (Copper Contributor)