cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ITDave
Level: Powered On

Deleting old files from sharepoint folder

Hi @gamoraes

 

Hi @ITDave if possible can you open a new Thread?

 

I am new to Flow, I thought it would be much simpler lol.

 

Can you give me a template or tell me exactly what i need to make this flow work?

 

ITDave

17 REPLIES 17
Community Support Team
Community Support Team

Re: Deleting old files from sharepoint folder

Hi @ITDave,

 

Would you please rearrange your needs here and post it out?

Maybe we could also provide the right workaround for you.
Please provide more details about your needs, it is best to attach a screenshot of the Flow configuration.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ITDave
Level: Powered On

Re: Deleting old files from sharepoint folder

Hi @v-bacao-msft

 

So I am trying to create a flow to remove old files from a sharepoint folder. The folder in question is a sub folder in the files area of a team. I have created a Recurrence that checks every hour. Get Files (properties only) on the Team area and the Library name is the folder that I want to remove files from. Then I want to delete the files that are older than the condition set. When I test the flow I get an error 404 list/item not found....

Screenshot_2.jpgScreenshot_3.jpgScreenshot_5.jpg

 

Help please 🙂

 

ITDave

Esmond
Level: Power Up

Re: Deleting old files from sharepoint folder

What I can see from my own experience is that your sub folder is too deep for the flow to run. It only allows 1 level sub folder from the "Documents" folder to work. Do a Test with your Flow where your sub folder is directly under the "Documents" folder with a few files.

Community Support Team
Community Support Team

Re: Deleting old files from sharepoint folder

Hi @ITDave ,

 

The reason that seems to cause the error is that the configuration of Library Name and List Name does not meet the requirements.

The Get files action can only select the root directory of the Library. This action can only get all the files in the current Library. There is no way to select the specified folder.

You need to use Condition to filter the files in the specified folder.

Please refer to the following method to configure your Flow:

  • I created a similar folder on my side, there are two subfolders.

40.PNG41.PNG

  • Use Folder path to determine if the file is a file in the specified folder. I added a condition to determine that it is a folder, because Get files action will also get all the folders.
  • If the file meets the set criteria, use Delete file action to delete the file directly.

Expression reference:

utcNow('yyyy-MM-dd')

is greater than

formatDateTime(addMinutes(items('Apply_to_each'),60),'yyyy-MM-dd')

42.PNG

Please take a try. Sorry for late reply.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ITDave
Level: Powered On

Re: Deleting old files from sharepoint folder

Hi @v-bacao-msft 

 

I am still having problems. I usered the following condition - As yours:

 

Screenshot_2.jpg

 

I get the following error:

Screenshot_1.jpg

 

Any idea what is going wrong now?

 

Best regards

 

ITDave

Community Support Team
Community Support Team

Re: Deleting old files from sharepoint folder

Hi @ITDave ,

 

My mistake, the expression seems to be missing a part.

Try using the following expression:

formatDateTime(addMinutes(items('Apply_to_each')['Created'],60),'yyyy-MM-dd')

Note: each is lowercase

Please take a try again and let me know if issue still exist.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Community Support Team
Community Support Team

Re: Deleting old files from sharepoint folder

Hi @ITDave ,

 

Do you need any other assistance?

 

Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
ITDave
Level: Powered On

Re: Deleting old files from sharepoint folder

Hi @v-bacao-msft 

 

Im afraid it is still not working. 

 

ITDave

Community Support Team
Community Support Team

Re: Deleting old files from sharepoint folder

Hi @ITDave ,

 

Any issue?

Please provide more details.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ITDave
Level: Powered On

Re: Deleting old files from sharepoint folder

Hi again @v-bacao-msft 

 

This is the error I now get when running the flow.... 😞

 

Screenshot_1.jpg

Community Support Team
Community Support Team

Re: Deleting old files from sharepoint folder

Please try this expression:

 

formatDateTime(addMinutes(items('Apply_to_each')['Created'],60),'yyyy-MM-dd')

 

Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ITDave
Level: Powered On

Re: Deleting old files from sharepoint folder

Hi @v-bacao-msft,

 

I think we are getting a little closer! 🙂

 

This time the flow ran succesfully but no files were deleted. Again the error is below....

 

 

Best regards

 

ITDave

Screenshot_2.jpg

Community Support Team
Community Support Team

Re: Deleting old files from sharepoint folder

Hi @ITDave ,

 

The reason for false is that one of the conditions set in Condition is not met.

 

First make sure that the configured Folder path is the same as the Folder path you are currently testing.

 

In addition, the date not match may be the main reason, you could try to use Compose to output utcNow('yyyy-MM-dd') and formatDateTime(addMinutes(items('Apply_to_each')['Created'],60),'yyyy-MM -dd') values to see if they are equal.

 

37.PNG

It is recommended to create a new Library or a new folder to test to prevent accidental deletion of files.

Take a try again.

 

Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ITDave
Level: Powered On

Re: Deleting old files from sharepoint folder

Hi @v-bacao-msft 

 

So I have gone back to basics:

Screenshot_1.jpg

 

With the above I can delete ALL files in ALL folders leaving the folder structure intact. I cannot get the FOLDER PATH to read my folder structure. Can we make this work first? The files I want to delete are in the highlighted folder:

Screenshot_4.jpg

What should I type in this box?

Screenshot_3.jpg

 

I have tried:

\Documents\General\Email Messages\

Documents\General\Email Messages\

\General\Email Messages\

General\Email Messages\

 

None of the above seem to work... Nothing gets deleted.

 

If we can sort this part then we can look at checking the files properties for the date?

 

 

Best regards

 

ITDave

Community Support Team
Community Support Team

Re: Deleting old files from sharepoint folder

Hi @ITDave ,

 

It seems that the Folder path should be Documents/General/Email Messages/.

You can get the Folder path in this way.

Put a file in the specified folder and use Get file properties action to get the Folder path, which is the one you want to configure in your Flow.46.PNG

 

44.PNG

 

45.PNG

 

Please take a try.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ITDave
Level: Powered On

Re: Deleting old files from sharepoint folder

Good morning Barry @v-bacao-msft 

 

We are definately getting somewhere now! I can delete files from the correct folder.

 

So I tried re-applying the utcNow and the formatDateTime but nothing is getting deleted. I ran compose to get results.

Screenshot_3.jpgScreenshot_1.jpg

If I change '60' to any other number in the formatDateTime I get the same results:

 

formatDateTime(addMinutes(items('Apply_to_each')['Created'],1),'yyyy-MM-dd')

 

Is there a different way of checking when the file was created?

 

Best regards

 

ITDave

 

 

Community Support Team
Community Support Team

Re: Deleting old files from sharepoint folder

Hi @ITDave ,

 

Use such an Expression to get Created Date:

 

items('Apply_to_each')['Created']
formatDateTime(items('Apply_to_each')['Created'],'yyyy-MM-dd')

56.PNG

I think your needs have been basically solved, you can consider creating new files to do some testing.

 

Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 132 members 5,326 guests
Please welcome our newest community members: