SOLVED

Deleting Files Automatically after 3 Months

%3CLINGO-SUB%20id%3D%22lingo-sub-2683088%22%20slang%3D%22en-US%22%3EDeleting%20Files%20Automatically%20after%203%20Months%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2683088%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20it%20possible%20to%20create%20a%20flow%20that%20will%20automatically%20delete%20files%20in%20specific%20SPO%20folders%20after%203%20months%3F%20I%20have%20tried%20using%20a%20flow%2C%20but%20I%20am%20not%20experienced%20with%20them%20and%20am%20having%20trouble.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2683088%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2683407%22%20slang%3D%22en-US%22%3ERe%3A%20Deleting%20Files%20Automatically%20after%203%20Months%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2683407%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1137183%22%20target%3D%22_blank%22%3E%40Filmanac%3C%2FA%3E%26nbsp%3Byes%20this%20can%20be%20done%20with%20a%20simple%20flow%20in%20Power%20Automate%20as%20shown%20below.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20Your%20trigger%20needs%20to%20be%20a%20recurrence%20schedule%20which%20you%20set%20to%201%20day%20(and%20the%20timezone%20and%20time%20you%20want%20it%20to%20run)%20so%20that%20it%20checks%20the%20library%20every%20day%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%221-Flow.png%22%20style%3D%22width%3A%20638px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F305633iF3A3F4EF6A13C3FA%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%221-Flow.png%22%20alt%3D%221-Flow.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20the%20first%20action%20select%20the%20SharePoint%20get%20files%20(properties%20only)%2C%20select%20your%20site%20and%20the%20Document%20library.%20But%20you%20only%20want%20to%20bring%20back%20those%20items%20that%20were%20created%20over%203%20months%20ago%2C%20the%20rest%20you%20can%20ignore.%20So%20in%20the%20Filter%20Query%20field%20add%20the%20following%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSPAN%3ECreated%20lt%20'%7Bexpression%7DaddDays(utcNow()%2C%26nbsp%3B-90)%7B%2Fexpression%7D'%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(%3CEM%3ECreated%3C%2FEM%3E%20is%20the%20column%20that%20is%20being%20checked%2C%20%3CEM%3Elt%3C%2FEM%3E%20%3D%20less%20than%2C%20%3CEM%3EutcNow()%3C%2FEM%3E%20%3D%20today%2C%20%3CEM%3E-90%3C%2FEM%3E%20is%2090%20days%20ago).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDon't%20forget%20to%20put%20the%20expression%20inside%20single%20quotes!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%222-Flow.png%22%20style%3D%22width%3A%20866px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F305635i018603E6B5622B11%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%222-Flow.png%22%20alt%3D%222-Flow.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20will%20default%20to%20bringing%20back%20items%20from%20the%20entire%20document%20library%20but%20you%20can%20limit%20it%20to%20a%20specific%20folders%20by%20clicking%20the%20folder%20icon%20on%20the%20right%20and%20selecting%20the%20folder%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%222a-Flow.png%22%20style%3D%22width%3A%20670px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F305632i3D92E0A24F88739D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%222a-Flow.png%22%20alt%3D%222a-Flow.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFinally%2C%20add%20a%20SharePoint%20delete%20file%20action.%20It%20will%20automatically%20wrap%20itself%20in%20an%20apply%20to%20each%20(as%20the%20previous%20action%20was%20get%20item%3CU%3E%3CSTRONG%3Es%3C%2FSTRONG%3E%3C%2FU%3E).%20Select%20%3CEM%3EIdentifier%3C%2FEM%3E%20from%20the%20dynamic%20content%20box.%20The%20items%20that%20were%20brought%20back%20by%20the%20get%20items%20will%20then%20be%20deleted.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%223-Flow.png%22%20style%3D%22width%3A%20874px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F305634i4454C4B0BD691AFA%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%223-Flow.png%22%20alt%3D%223-Flow.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERob%3CBR%20%2F%3ELos%20Gallardos%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%23006400%22%3EMicrosoft%20Power%20Automate%20Community%20Super%20User%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2686882%22%20slang%3D%22en-US%22%3ERe%3A%20Deleting%20Files%20Automatically%20after%203%20Months%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2686882%22%20slang%3D%22en-US%22%3EHello%20Rob%2C%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20for%20the%20instructions%20on%20this.%20It%20made%20everything%20much%20clearer.%20The%20flow%20runs%20successfully%20in%20both%20test%20and%20when%20left%20to%20itself%20based%20on%20the%20time%20margin%2C%20however%2C%20files%20older%20than%203%20months%2F90%20days%20are%20not%20being%20deleted.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20made%20sure%20to%20include%20nested%20items%2C%20so%20not%20sure%20what%20is%20stopping%20things%20now.%20I%20will%20need%20to%20dig%20a%20bit%20deeper.%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20for%20your%20help%20so%20far%20though.%3C%2FLINGO-BODY%3E
New Contributor

Hello, 

 

Is it possible to create a flow that will automatically delete files in specific SPO folders after 3 months? I have tried using a flow, but I am not experienced with them and am having trouble.

 

Thanks. 

 

 

4 Replies
best response confirmed by Juan Carlos González Martín (MVP)
Solution

@Filmanac yes this can be done with a simple flow in Power Automate as shown below.

 

1. Your trigger needs to be a recurrence schedule which you set to 1 day (and the timezone and time you want it to run) so that it checks the library every day:

1-Flow.png

 

For the first action select the SharePoint get files (properties only), select your site and the Document library. But you only want to bring back those items that were created over 3 months ago, the rest you can ignore. So in the Filter Query field add the following:

Created lt '{expression}addDays(utcNow(), -90){/expression}'

 

(Created is the column that is being checked, lt = less than, utcNow() = today, -90 is 90 days ago).

 

Don't forget to put the expression inside single quotes!

 

2-Flow.png

 

It will default to bringing back items from the entire document library but you can limit it to a specific folders by clicking the folder icon on the right and selecting the folder:

2a-Flow.png

 

Finally, add a SharePoint delete file action. It will automatically wrap itself in an apply to each (as the previous action was get items). Select Identifier from the dynamic content box. The items that were brought back by the get items will then be deleted.

 

3-Flow.png

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

Hello Rob,

Thank you for the instructions on this. It made everything much clearer. The flow runs successfully in both test and when left to itself based on the time margin, however, files older than 3 months/90 days are not being deleted.

I have made sure to include nested items, so not sure what is stopping things now. I will need to dig a bit deeper.

Thank you for your help so far though.
If you post a screenshot of your flow then we can see where you've gone wrong.

@RobElliott I have attached two screenshots of the flow. I haven't included it in the screenshot, but the code I'm using for the filter query is 'addDays(utcNow(),-90). 

 

I have removed the actual SharePoint site address and the specific folder I'm using.