web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Copy a folder/file if ...
Power Automate
Answered

Copy a folder/file if this (Folder/File) was modified the last week/Month to another folder

(0) ShareShare
ReportReport
Posted on by 11

Hey Everyone,

 

I am very new to Power Automate Desktop so I would appreciate a detailed template on this as it's the only one I want.

 

I want to have a flow in which if a folder/File was modified the Past 7 days then this file should be copied to another folder and also overwritten if the same file exists already.

 

Basically i am trying to copy ONLY modified files or folders to my OneDrive Folder instead of manually doing it since OneDrive doesn't have selective syncs to custom folders and I want it to be overwritten if there was already a folder/file with the same name.

 

Appreciate the Support and thank you for reading.

  • SunnyJoshi Profile Picture
    14 on at

    Hello You can choose as per attached action and set up days or last seven or as per your requirements.

     

    if you issue resolved please mark it as solved give your feedbay

  • SunnyJoshi Profile Picture
    14 on at

    C3CF8401-6EE6-4A2E-BF9F-F8C251135958.jpeg

  • Ave1 Profile Picture
    11 on at

    My source file is from my local disk to my destination file which is my OneDrive folder 

    So that's why i wanted to use Power Automate Desktop and not a Cloud flow since it doesn't have the option

  • jusTodd Profile Picture
    on at

    Struggling with a similar situation, wanting to overwrite files that have changed.

     

    It probably does not help much, but the following link seems to indicate that it is possible to get "LastModified" from a file.

     

    Variable data type properties - Power Automate | Microsoft Learn

     

    Will post back if I figure it out.

  • Ave1 Profile Picture
    11 on at

    I understand that but how do I add to copy the files that were last modified within the past week

     

    Am sure there must be some formula to add but i don't have enough knowledge to where i can find it 

  • VJR Profile Picture
    7,635 on at

    Hi @Ave1 

    I assume you have a locally mapped folder of the corresponding OneDrive folders.

     

    Meaning, there would be a location on your, let's say C: drive, where all the OneDrive folders are synced.

    Let's call it C:\OneDrive\LocalFiles

     

    - Use the Get files in folder on the above folder

    - Use the For Each loop to iterate within these files. Check which file has the last modified date within the last week as suggested by @jusTodd.

    - Use the Copy file(s) action for that file

     

    Which part are you finding it challenging?

  • Ave1 Profile Picture
    11 on at

    Thank you for the suggestion. @VJR 

     

    Since i am abit new to this then i will give an example so everything would be clear

     

    I have a folder with subfolders in local disk E (Like: E: Folder/subfolder) , there are already files inside these folders that were modified one year ago and there are some last modified 7 days ago 

     

    I already have a copy of this folder in my OneDrive folder to be synced of course to Cloud 

     

    The flow that i want is to copy the last modified files from the past 7 days (for example, E:\Documents\Word\file.docx) and to be copied to my OneDrive folder with it's respective sub folder that it was on which will be (C:\Users\Username\OneDrive\Documents\Word\file.docx) and be overwritten if the same name is available 

     

    I don't' want the entire Documents folder to be copied , just only the file that was last modified 

     

    I hope i made it clear enough but if there is anything else you would like me to clarify please let me know

     

    Also if u can show me a rough graph of it or image of the steps that would be much appreciated 

  • Verified answer
    VJR Profile Picture
    7,635 on at

    Hi @Ave1 

     

    Copy paste the below code into a blank flow editor.

    Make changes for path etc.

    At first don't run this on the original files and folders. Run this on a test folder.

    Refer to the comments mentioned in the Flow.

    Remove message boxes that you don't need.

    Without the folder structure like yours, I have tried to write the code as much as possible. Hope you get to work it out.

     

    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    # The date time that was 7 days ago will be stored in the variable called %SevenDaysAgoDate%
    DateTime.Add DateTime: CurrentDateTime TimeToAdd: -7 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> SevenDaysAgoDate
    DISABLE Display.ShowMessageDialog.ShowMessage Message: $'''Date time that was 7 days ago: %SevenDaysAgoDate%''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
    # Change the path on the below folder to your local files folder
    Folder.GetFiles Folder: $'''E:\\Folder\\SubFolder''' FileFilter: $'''*.xlsx''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.LastModified SortDescending1: True SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    # Set the path of the OneDrive folder where the files will be copied
    SET MyOneDriveRootFolder TO $'''C:\\Users\\Username\\OneDrive\\Documents\\'''
    LOOP FOREACH CurrentItem IN Files
     Display.ShowMessageDialog.ShowMessage Message: $'''Last modified date time of current file: %CurrentItem.LastModified%''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
     # Get the parent folder of the local files folder
     File.GetPathPart File: CurrentItem Directory=> Directory
     Text.SplitText.SplitWithDelimiter Text: Directory CustomDelimiter: $'''\\''' IsRegEx: False Result=> TextList
     SET ParentFolderName TO TextList[TextList.Count - 1]
     Display.ShowMessageDialog.ShowMessage Message: $'''The parent folder name is: %ParentFolderName%''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed2
     IF (Folder.IfFolderExists.Exists Path: $'''%MyOneDriveRootFolder%\\%ParentFolderName%''') THEN
     # Folder exists. No need to create new folder. Leave this action as it is.
     ELSE
     # Folder does not exists. So create one.
     Folder.Create FolderPath: MyOneDriveRootFolder FolderName: ParentFolderName Folder=> DestinationFolder
     END
     # Check if the file was modified within the last 7 days
     IF CurrentItem.LastModified >= SevenDaysAgoDate THEN
     # Within the last 7 days - COPY THE FILE. Overwrite if it exists
     File.Copy Files: CurrentItem Destination: DestinationFolder IfFileExists: File.IfExists.Overwrite CopiedFiles=> CopiedFiles
     ELSE
     # NOT Within the last 7 days - DO NOTHING
     END
    END
    Display.ShowMessageDialog.ShowMessage Message: $'''Done''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed3
    

     

    How to copy-paste the above code into PAD:

     

    Copy Paste Desktop Flows.gif

     

  • VJR Profile Picture
    7,635 on at

    Here are some free training materials that will get you upto speed on Power Automate Desktop.

     

    The official training modules for Power Automate Desktop is this. 

    Scroll down to where it says "Items in this collection".

    Exam PL-500: Microsoft Power Automate RPA Developer - Certifications | Microsoft Learn

     

    Below are some free YouTube training content

    Microsoft Power Automate Desktop For Beginners [2022] - YouTube

     

    This one explains every single action of Power Automate Desktop

    Microsoft Power Automate Desktop - YouTube

  • abusleem Profile Picture
    2 on at

    hello m hope u doing well , 

    u can do it in easy way just follow this : 
    add new Variable before the flow , just in defult Value right that : %Files.LastModified%   and click save , thx in advance 

    abusleem_0-1682631652353.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 259 Super User 2026 Season 2

#2
11manish Profile Picture

11manish 227 Super User 2026 Season 2

#3
Valantis Profile Picture

Valantis 134 Super User 2026 Season 2

Last 30 days Overall leaderboard