cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
igonzalez1
Frequent Visitor

Move files to a folder based on last modified date

I want to move files that are older than a day to a different folder based on their last modified date.

For example, move File1 that was last modified on Jan 14, 2021 to ...reports\2021\01\14. Repeat this for every file in ...reports\ (not including sub folders). The path structure is simply yyyy\mm\dd (if this subfolder does not exist, create it).

 

How can I go about that?

1 ACCEPTED SOLUTION

Accepted Solutions
manuelstgomes
Community Champion
Community Champion

Hi @igonzalez1 

 

I'm going to assume that the files are in your OneDrive, but the process is the same if they are in SharePoint.

 

For the condition to take one day

addDays(utcNow(),-1)

 

To get the day, month, and year:

formatDateTime(items('Apply_to_each')?['LastModified'],'dd')
formatDateTime(items('Apply_to_each')?['LastModified'],'MM')
formatDateTime(items('Apply_to_each')?['LastModified'],'yyyy')

 

And here's the full Flow:

Screenshot_2021-02-09_at_18_56_55.jpg

 

Can you please check if and let me know if you have any questions?

 

Cheers
Manuel

-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

3 REPLIES 3
manuelstgomes
Community Champion
Community Champion

Hi @igonzalez1 

 

I'm going to assume that the files are in your OneDrive, but the process is the same if they are in SharePoint.

 

For the condition to take one day

addDays(utcNow(),-1)

 

To get the day, month, and year:

formatDateTime(items('Apply_to_each')?['LastModified'],'dd')
formatDateTime(items('Apply_to_each')?['LastModified'],'MM')
formatDateTime(items('Apply_to_each')?['LastModified'],'yyyy')

 

And here's the full Flow:

Screenshot_2021-02-09_at_18_56_55.jpg

 

Can you please check if and let me know if you have any questions?

 

Cheers
Manuel

-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Hi @manuelstgomes 

Thank you very much. Yes, it's OneDrive for Business. Couple of questions:

  1. Does 'List files in folder' include subfolders? If so, how to disable it? If it doesn't, how can I make it include subfolders? I don't see an option.
  2. Is 'List files in folder' updated after every loop of 'Apply to each'? I hope not.
manuelstgomes
Community Champion
Community Champion

Hi @igonzalez1 

 

The "List files in the folder" list the whole contents of a folder (folders and files) and return a flag (isFolder) so that you know if an entry is a file or a folder. It won't drill down if you want to do that; you need to do a more complex Flow where if it finds a folder, it will call another Flow (or the same one) to find information under that directory recursively. I can show you how, but it's a little bit more tricky. 

 

Regarding your second question, no. The Flow fetches all the information in the "List files in folder" step and uses it until the flow. Each action is always like a snapshot. It collects the data as it is at the moment.

 

Cheers
Manuel

-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,779)