Skip to main content

Notifications

Power Automate - Building Flows
Unanswered

SharePoint File From Folder to Folder Transfer

Posted on by 4
I've been trying to crack through this flow for a bit now and it keeps throwing all kinds of different errors no matter which way I've tried. I've attempted conditional True/False checks on last modified file dates, now trying to get a filter array to do the job (which has gotten me the furthest so far).
 
The goal is to get an automatic archive function setup so that every three months it checks a folder for any files that are older than 730 days (two years), and moves them over to an archive folder.
 
I keep getting to the move function and it kicks back telling me it "can't find the file", despite identifying it in the code, but failing when it goes to move it.
 
createArray(outputs('Get_files_(properties_only)')?['LastModified'])
addDays(utcNow(), -730)
 
The "For Each" is set to (SP) body/value
 
The Move file-copy is this:
 
 
So what am I missing? How do I get this to run?
  • creativeopinion Profile Picture
    creativeopinion 9,897 on at
    SharePoint File From Folder to Folder Transfer
    Your Filter Query is still incorrect. As mentioned the Created and Modified timestamps include a time. You need to ensure that your filter query includes the following: 
    • A start timestamp (12:00 AM) for the beginning of the day.
    • An end timestamp (11:59 PM) for the end of the day.
     
    As recommended in my previous post. Use a Compose action to compose the start timestamp and end timestamp 730 days ago. 
     
    I would also recommend inserting two additional actions before the Apply to Each loop. You need to ensure that your Get Files (properties only) action is returning the number of files you are expecting first before you even try to loop through them. You have to ensure that the Filter Query is filtering out the files as expected.
    For that reason, I would first insert a Compose action to return the number of files. Refer to this section of my YT Tutorial where I cover how to do this. 
     
    I would also recommend adding a Terminate action after the Compose action. This will prevent the Apply to Each (for each) action from running.
     
     
     
     
    Run a test and toggle off the new designer. Show the outputs of your Compose actions.
  • SharePoint File From Folder to Folder Transfer
    @creativeopinion First off, I appreciate you taking the time to try and help me with this, I really do.
     
    I decided to try a from-scratch approach as you laid it out in your last example, step by step, and... got stopped hard at trying to filter the properties, it kept kicking back that "LastModified" wasn't valid. From this I tried altering "LastModified" to "Created" which passes, but once I move on to Composing the list slash setting up the Move File, it varies between ActionFailed or ActionSkipped. I tried using the compose output for the move as well as just plugging in the move directly in a basic for_each.
     
    In a desperate attempt I took what you were talking about and went all the way back to the simplest I could think to make a move action:
     
    With the Get query filtered to this:
    -with the function just being addDays(utcNow(), -730))
    -yes Pagination has been turned on the entire time, but I only ever set them to 100 because it seemed to lag too long in tests at 1,000.
    -and the move file is set with the SP {Identifier}
    And I get to here:
    But the test never moves past this, I don't get any errors, but it never "passes" or completes. The output window is showing the right type of files in the parameters tab that it's grabbing, and in the simplest form of the move process that I've looked up something as straight forward as this should do the job, but doesn't seem to, I am at a loss.
  • creativeopinion Profile Picture
    creativeopinion 9,897 on at
    SharePoint File From Folder to Folder Transfer
    @ProgrammingCoffee Is this a screenshot from your Filter Array action? If so the logic behind this is incorrect.
     
    createArray(outputs('Get_files_(properties_only)')?['LastModified']):
    This creates an array of LastModified dates for files retrieved by the Get files (properties only) action. Each file’s LastModified date indicates when it was last modified.

    addDays(utcNow(), -730)
    This subtracts 730 days (2 years) from the current date/time (utcNow()) to calculate a date in the past. Eg (Output of November 29, 2022, 14:30:00 UTC)

    Why the Logic Doesn't Work

    Your filter query is using a static function in the value fields. It doesn't reference any items from the array. Your filter should evaluate the items. In your case, since you are looking at the Modified date of the files the Filter Array action isn't necessary (as previously mentioned)/

    Instead, you need to use the Filter Query in the Get Files (properties only) action. 

    Compose the Timestamps

    Whenever I work with dates and times I find it easier to place the expression in a Compose action and run tests to ensure the expression is outputting as expected. Tip: Always rename your actions to keep your flow organized. This is especially helpful when you are using more than one instance of the same action.
     
    This can help speed up your flow building process. In your case, use a Compose action and store the following expression:
    formatDateTime(addDays(utcNow(), -730), 'yyyy-MM-ddTHH:mm:ssZ')
     
     
    Run a test. Review the outputs. The output will display a date from two years ago at the exact time you ran the flow (e.g., if you ran it at 3:45 PM, the output will show 3:45 PM two years ago).
     
    However, if your intention is to consider the entire day two years ago (all 24 hours), you’ll need to manually create:
    • A start timestamp (12:00 AM) for the beginning of the day.
    • An end timestamp (11:59 PM) for the end of the day.
    This ensures you include all data for that day, regardless of the time it was modified.
     
    Edit the expression by clicking on it and adjusting the time to 00:00:00 (for 12 AM). Don't forget to press Update to save your changes.
    You can hover over the label to ensure that the change has been made.
     
    Duplicate the action by clicking on the three dots and selecting Copy to Clipboard.
     
    Click + Next step. Click on My Clipboard and then click on your copied action to insert it.
     
     
    Don't forget to rename your action.
     
    Click on the expression to edit it and adjust the time so it's 11:59 PM. Don't forget to press update to save your changes.
    Run a test. Review the outputs.

    Get Files (Properties Only)

    This action returns files and folders. To filter out files only you can use the following filter query:
    FSObjType eq 0
    
    You can also add the arguments to check the modified date.
    FSObjType eq 0 and LastModified ge '[Compose Start Date]' and LastModified le '[Compose End Date]'
    
    The filter query logic is as follows:
    FSObjType eq 0:
    Ensures only files are retrieved, excluding folders.
     
    LastModified ge '[Compose Start Date]'
    Filters for files modified on or after the start date provided by the Compose action with the Two Year Start Date.
     
    LastModified le '[Compose End Date]'
    Filters for files modified on or before the end date provided by the Compose action with the Two Year End Date.

    Toggle On Pagination

    Additionally, the default limit of files returned by the Get Files (properties only) action is 100. You will need to toggle on pagination. Click on the three dots of the Get Files (properties only) action. Select Settings.
     
    Toggle on pagination and set a threshold. Scroll down and press done. Keep in mind that retrieving a large number of items can slow down your flow significantly. It’s always better to filter results as much as possible to minimize the number of items retrieved.

     

    Return Count of Items

    Whenever I use a Filter Query in a Get Items action, I always like to return the count of items returned in a Compose action. This is helpful when building a flow and can also be used to troubleshoot your flow.

    Insert a Compose action. Add an Expression. Use the length() function.

    Select the Dynamic content tab and insert the value dynamic content from the Get Items action into the length() function.


    Run a test.
     

    Condition Check

    Add a Condition action to your flow. If items have returned (aka there is number stored in the Compose action—that is not equal to 0), add the rest of your actions to the Yes branch. If not, do nothing.
     
    Hope this helps!
  • SharePoint File From Folder to Folder Transfer
    @creativeopinion I'm not sure what else you think is missing from the flow, I posted all the elements.
     
    In regards to filter query versus the filter array, I tried query and doing a conditional result, that method consistently did not return any form of a result. The array is explicitly separating out the files I'm targeting (older than two years/730 days), the problem isn't even with the array, it's with the move:
     
    Action 'Move_file-copy' failed: Failed to verify the existence of destination location --redacted-- due to error 'The system cannot find the file specified. (Exception from HRESULT: 0x80070002)'.
     
    And in the code I can see it targeting specific files at the original box location, but it's failing to complete the move process. I can't seem to get this functioning in a way where it applies the right container to the files through the flow to move them.
     
    I have tried doing a straight filter in the properties step but it won't pass to the next level stating that there's a failed column, and when I try and tell it to ignore failed columns, it just won't process at all.
     
    If I break down into a conditional check instead of an array, it won't pass because it tells me there's an unchecked branch.
  • creativeopinion Profile Picture
    creativeopinion 9,897 on at
    SharePoint File From Folder to Folder Transfer
    @ProgrammingCoffee It's hard to offer any recommendations without seeing your full flow and the logic behind it. Toggle off the New Designer and click each action to expand it. Upload a screenshot of your flow in edit mode.
     
    From what I can gather with the screenshots you have shared is that you aren't using the proper dynamic content in the Move File action. You also need to ensure you are looping through your Filter Array action items and not the items returned from the Get Files (properties only) action. The Filter Array action may not be necessary in your case. You should consider defining a Filter Query in the Get Files (properties only) action.
     
    You need to use the Identifier dynamic content in the Files to Move field.
     
     
     
    To learn more about the filter array action, check out this YT Tutorial:
     

    In this video tutorial I’ll show you 3 practical ways to use the Filter Array action and how to use it properly.
    1️⃣ Cross-Referencing Data
    2️⃣ Filtering by Key
    3️⃣ Substring Matching
    Did you know that the Condition action has a limit of 10 conditions? Although it might look like the Filter Array action can only accept one condition—this is not true. By using the advanced mode you can enter multiple conditions into a Filter Array action with an expression.

    IN THIS VIDEO:
    ✓ 3 Ways to Use the Filter Array Action
    ✓ How to use the Scope Action to Group Actions
    ✓ How to Check the Number of Items returned from a Filter Array Action
    ✓ How to Cross-Reference Data in Excel with a SharePoint List
    ✓ How the Filter Array Action Works
    ✓ How to Access the Dynamic Content from a Filter Array Action
    ✓ How to Filter Items by a Key
    ✓ How to Filter Items by Matching a Substring
    ✓ How to Use Multiple Conditions in a Filter Array Action
     
     
    You also might be interested in this YT Tutorial: 
     
    3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow
    In this video tutorial I’ll go over how to avoid these common mistakes when using the Apply to Each action in a Power Automate flow:
    1️⃣ Looping through a Single Item
    2️⃣ Creating Unnecessary Nested Loops
    3️⃣ Looping through an Unfiltered Array

    At the end of the video I share a few helpful insights when it comes to using the Apply to Each action in your flow.

    IN THIS VIDEO:
    ✓ How to avoid the Apply to Each action with a single item array
    ✓ How to use the item() function to access dynamic content in an array
    ✓ How to prevent unnecessary nested Apply to Each action loops
    ✓ How to use the Select action
    ✓ How to convert an array to a string with the Select action
    ✓How to use the Filter Query field
    ✓ How to count the number of items in an array
    ✓ How to use a condition control
    ✓ How to use the concurrency control
    ✓ How to set a top count
    ✓ How to use Compose actions for troubleshooting
     
     
    Hope this helps!
    Consider giving me a ❤️ if you liked my response!

    👉 Level up your Power Automate skills by checking out my tutorials on YouTube
    👉 Tips and Tricks on TikTok and Instagram
  • xanddix Profile Picture
    xanddix 18 on at
    SharePoint File From Folder to Folder Transfer
    Hello, the filter array actions worked? or you still trying to solve it

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,297

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,890

Leaderboard