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 / Error message: Paramet...
Power Automate
Answered

Error message: Parameter 'Folder' Argument must be 'Folder'

(0) ShareShare
ReportReport
Posted on by 20

I'm trying to build a flow which will eventually run a loop. It will read values from a list of individual Excel files and write them to a single master Excel file. I have more or less figured out how to write the steps for the loop, but only when all the individual Excel files are stored into one folder. However, I want to figure out how to deal with a situation where the loop can work even when these individual Excel files are stored in a series of disparate folders. 

 

For reference, the individual Excel files are now stored in various subfolders, all with the same name of 'Docs':

JM12345_0-1708791430254.png

 

So my first command for PAD is to "Get subfolders in folder", with the folder path as 'File 1', and the folder filter as 'Docs' (see above: File 1 is the main folder in which various subfolders exist):

JM12345_1-1708791492925.png

 

As far as I can tell, this works when run. PAD correctly collects every folder with the name 'Docs' and stores them in the Variable value: %Folders%

JM12345_2-1708791570732.png

 

Next, what I want to do is retrieve only the files in these folders with the extension .xlsx, and store them into a %Files% variable so I can run the loop.

 

But for some reason, I keep getting an error message when I try to use the %Folders% variable as a starting point for this action:

JM12345_4-1708786691381.png

I don't get it...what am I doing wrong? 

I have the same question (0)
  • Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    Hi @JM12345 , Hope you are doing well!!

     

    Yeah, the "Get files in folder" action expects a string value for the folder path. However, in the screenshot above, you are passing a list as the input value, which is why the error is appearing.

     

    Please follow the steps outlined below:

    1. Utilize the "Get subfolders in folder" action to retrieve a list of subfolder names. For instance: "Folders (Data type: List)".

    2. Proceed to iterate through the list values using a for-each loop. This allows you to access each folder name individually within the loop as the current item. You'll then pass this current item into the "Get files in folder" action and apply a filter such as "*xlsx".

    3. You'll subsequently receive another list containing all your Excel files.

     

    Please find below the suggested flow for the same use case:

     

    Deenuji_0-1708793397058.png

    Deenuji_1-1708793500809.png

     

    Code(you can copy/paste the below code in your PAD designer screen):

     

    Folder.GetSubfolders Folder: $'''C:\\Desktop\\PA test 1\\File 1''' FolderFilter: $'''Docs''' IncludeSubfolders: True FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Subfolders=> Folders
    LOOP FOREACH CurrentItem IN Folders
    Folder.GetFiles Folder: CurrentItem FileFilter: $'''*xlsx''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    Display.ShowMessageDialog.ShowMessage Title: $'''test''' Message: Files Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed
    END

     

    Thanks,

    Deenu

     

    ------------------------------------------------------------------------------------------------------------

     

    If I've successfully resolved your queries, please consider accepting this as the solution 🎉 and giving it a thumbs up 👍 . Your feedback is greatly appreciated!

  • JM12345 Profile Picture
    20 on at

    Hi Deenuji,

    I tried this, but I'm not sure I'm getting the result I want. Here's the setup, it's very similar to your instruction:

    JM12345_1-1708794564666.png

    When I run the 'for each' loop to get the files, I only seem to be retrieving a single file:

    JM12345_0-1708794462514.png

    There should be three separate Excel files listed here, I believe (one from each 'Docs' subfolder). 

     

  • Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @JM12345 

    If three Excel files exist in three different folders, then you will indeed obtain each file in three separate iterations, which seems to be working correctly.

     

    If this is not what you intended or if you have a different objective in mind, please let me know so that I can better understand what you are trying to achieve.

  • JM12345 Profile Picture
    20 on at

    Yes, there is an Excel file in each 'Docs' folder, as I said. However, the screenshot I posted, which was the result of the 'for each' loop for the %Files% variable, contains only one Excel file. There should be three extracted there, from what I'm understanding. 

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @JM12345 

     

    If your objective is to scan all the Docs folders within "File 1" folder and extract the paths of all Excel files into a single list, follow the suggested approach below:

     

    Deenuji_0-1708795580590.png

     

    Code:

    Variables.CreateNewList List=> ExcelFileList
    Folder.GetSubfolders Folder: $'''C:\\Desktop\\PA test 1\\File 1''' FolderFilter: $'''Docs''' IncludeSubfolders: True FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Subfolders=> Folders
    LOOP FOREACH CurrentItem IN Folders
    Folder.GetFiles Folder: CurrentItem FileFilter: $'''*xlsx''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    LOOP FOREACH CurrentFile IN Files
    Variables.AddItemToList Item: CurrentFile List: ExcelFileList
    END
    END
    Display.ShowMessageDialog.ShowMessage Title: $'''test''' Message: ExcelFileList Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed

     

     

     

     

    Thanks,

    Deenu

     

    ------------------------------------------------------------------------------------------------------------

     

    If I've successfully resolved your queries, please consider accepting this as the solution  and giving it a thumbs up . Your feedback is greatly appreciated!

  • JM12345 Profile Picture
    20 on at

    I think that worked:

    JM12345_0-1708796526969.png

    The ExcelFileList variable now contains the three individual Excel files from the Docs folders. I should be able to run the loop through those Excel files and write to the single master file, as needed.

    Thanks Deenuji!

  • Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @JM12345 

    I'm delighted that my answer has helped you achieve your goals. Thanks! Happy automation!!

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 267 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 196

#3
Haque Profile Picture

Haque 182

Last 30 days Overall leaderboard