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 / Moving Files to Folders
Power Automate
Answered

Moving Files to Folders

(0) ShareShare
ReportReport
Posted on by 39

Hi, I am trying to create folders with the values extracted from an Excel file and I also wish to move the certain Excel files to said folders, on the basis of the TaxID shared in the names of the folders and the Excel files. 

 

Here's the workflow for reference:

aSagCoder_0-1706886498124.pngaSagCoder_1-1706886542771.png

However, the actions in line 11 to 15 do not seem to be working, i.e. these actions are unable to move the files into the appropriate folders. Eg. - I wish to move any and all Excel files that have TaxID 'PT0829' into a folder named as 'PT0829', etc. 

 

Any and all advice is heartily welcomed. 

 

I have the same question (0)
  • ryule Profile Picture
    929 Super User 2024 Season 1 on at

    Your loop that starts on 11 is opening the folder you just created, so there would be no files in there yet. I think you would just need to Close Excel and move the file to TaxIDFolderName after your original loop

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    There are two issues with your flow:

    1. The second For each loop, as well as Get files in folder should be inside the first For each loop. This is because you want to process each Tax Id individually, and the first For each loop is where you do that. 
    2. The If condition inside the second For each loop is incorrect. You are checking if the entire list of files contains %TaxIDNo%, and not just the file. You should instead check if %CurrentExcelReport% contains it. 

    Alternatively, regarding point no. 2, you could simply add a filter into your Get files in folder action to filter for a specific %TaxIDNo%, and then you would not even need a second For each or a condition. You could simply use Move file(s) to move all those files. This is after you move it inside your first For each loop to process each Tax ID individually.

     

  • aSagCoder Profile Picture
    39 on at

    Hi, thank you for the suggestions! I tried to implement as you suggested. However, when I run the workflow I seem to encounter an error which indicates that the Destination Folder with %TaxIDNo% doesn't exist, even though it does exist. Is there any way I can resolve this issue?

  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    So, the first thing I see is that you ask for FirstFreeRow, but then you don't use it.  In the very next command you only pull B1 to B3, not to B and %FirstFreeRow%.  Therefore you will always only get 3 tax IDs (assuming no title row).  If you do have a title row, then you want to pull B2 to %FirstFreeRow%.

     

    From here, the logic is all backwards.  Like @Agnius said, we just want to "Get Files" using the Tax ID on the proper folder.  So the whole thing looks like this:

     

    First, as an input variable, have the path that stores all the TaxID folders, i'll call it %TaxID_MainPath%

    Open Excel Workbook

    Get %FirstFreeRow%

    Read from Excel B1 to %FirstFreeRow% (to get %TaxIDs%)

    For each %TaxID% in %TaxIDs%

        Get Files (Filter files for %TaxID%*.xlsx)  here, the asterisk represents anything after, so it will pull in something like %TaxID%_Financials.xlsx.

        Move Files %Files% to folder %TaxID_MainPath%\%TaxID% (the TaxID subfolder in MainPath)

    End (for each)

     

    This will read all tax id's from the excel workbook (to last row) and then will search for all files containing that Tax ID and move all those files to the appropriate folder before moving onto the next tax id.  This stops you from having to read all files first and picking them apart one by one.  It will be much faster and easier to build.

     

    Good luck!

  • aSagCoder Profile Picture
    39 on at

    Hi, thank you for answering! I implemented as per your comment, and also realized a small mistake I had committed - I was using the variable that had the file name and not the file path for moving folders and that was the reason why the workflow couldn't work as well. I made the necessary changes and it worked! Thank you and @Agnius again for helping me out. 

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 250 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 180

#3
Haque Profile Picture

Haque 159

Last 30 days Overall leaderboard