Top 3 best ways get all files in a folder using Power Automate

Top 3 best ways get all files in a folder Power Automate

No comments

 243 total views,  11 views today

In this “Get all files in a folder Power Automate” tutorial, we will learn how to get all files from a given folder in a SharePoint document library using Power Automate.

 

Method 1: Using Limit Entries to Folder to get all files in a folder Power Automate

Select your folder using the “Limit Entries to Folder” method, and get all files from the selected folder path.

Limit Entries to Folder to get all files in a folder Power Automate
Limit Entries to Folder to get all files in a folder Power Automate

Now, if we execute the Power Automate, we will get all files from the selected folder path: “/GSD Test Document Library/DS0001”

Limit Entries to Folder to get all files in a folder Power Automate demo
Limit Entries to Folder to get all files in a folder Power Automate demo

Notes:

  • The limit entries to folders option is available both in Get items and Get files (properties only).
  • Sometimes, the limit entries to folder option doesn’t work both in Get items and Get files (properties only). That means even if you have documents in the folder, it doesn’t retrieve them.
  • After getting the result from the Get Items or Get Files (properties only) method, you can loop through each document using the apply to each control loop.

 

Method 2: Using List Folder to get all files in a folder Power Automate

Add a list folder action and select your folder as in the above method.

Using List Folder to get all files in a folder Power Automate
Using List Folder to get all files in a folder Power Automate

In file identifier, click on the show picker icon, select your document library, and select your desired folder or document set.

Using List Folder click on the show picker icon to select your folder
Using List Folder click on the show picker icon to select your folder

Demo: Using List Folder to get all files in a folder Power Automate

Now, after successfully executing the flow, we will get all files from the selected folder path.

Using List Folder to get all files in a folder Power Automate - Demo
Using List Folder to get all files in a folder Power Automate – Demo

List Folder Output in Power Automate

Below is the output of List Folder execution (example with a single file):


  {
    "Id": "%252fGSD%2bTest%2bDocument%2bLibrary%252fDS0001%252fSample%2bFile%2b1.csv",
    "Name": "Sample File 1.csv",
    "DisplayName": "Sample File 1.csv",
    "Path": "/GSD Test Document Library/DS0001/Sample File 1.csv",
    "LastModified": "2022-12-10T14:49:35Z",
    "Size": 380,
    "MediaType": "text/csv",
    "IsFolder": false,
    "ETag": "\"{10951643-66B8-4EE9-AB1C-D665D7AF0BF8},4\"",
    "FileLocator": "dataset=aHR0cHM6Ly9nbG9iYWxzaGFyZXBvaW50MjAyMC5zaGFyZXBvaW50LmNvbS9zaXRlcy9HU0RSbkQ=,id=JTI1MmZHU0QlMmJUZXN0JTJiRG9jdW1lbnQlMmJMaWJyYXJ5JTI1MmZEUzAwMDElMjUyZlNhbXBsZSUyYkZpbGUlMmIxLmNzdg=="
  }
 

Metadata returns by List Folder action in Power Automate

Below are the metadata or file properties returned by the list folder action in Power Automate:

  • ID
  • Name
  • DisplayName
  • Path
  • LastModified
  • Size
  • MediaType
  • IsFolder
  • ETag
  • FileLocator

Note:

  • In the above list, “ID” is not an integer; it returns the file relative path. example given below. So, if you want to query a list item using Get Item or any other method using this ID parameter, it will not work.


"Id": "%252fGSD%2bTest%2bDocument%2bLibrary%252fDS0001%252fSample%2bFile%2b2.csv",

Disadvantage of List Folder action in Power Automate

As we see in the result, we cannot get the value of custom metadata columns in the list folder action; it returns only the out-of-the box file attribute. So, this method is not the right choice if you want to deal with custom metadata columns from the SharePoint Online document library.

Note:

  • Like the Get Items and Get Files (properties only) methods, we can loop through each item in the result of the folder action.

Method 3: Using the “Send an HTTP request to SharePoint” to get all files in a folder Power Automate

Using the “Send an HTTP request to SharePoint” Power Automate action, we can get all files in a folder.

Using the Send an HTTP request to SharePoint to get all files in a folder Power Automate
Using the Send an HTTP request to SharePoint to get all files in a folder Power Automate

URI:


_api/web/GetFolderByServerRelativeUrl('Your document library name/your folder name')/files

Output returns by GETFolderByServerRelativeUrl request REST API

{

  "d": {

    "results": [

      {

        "__metadata": {

          "id": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD Test Document Library/DS0001/Sample File 2.csv')",

          "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')",

          "type": "SP.File"

        },

        "Author": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/Author"

          }

        },

        "CheckedOutByUser": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/CheckedOutByUser"

          }

        },

        "EffectiveInformationRightsManagementSettings": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/EffectiveInformationRightsManagementSettings"

          }

        },

        "InformationRightsManagementSettings": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/InformationRightsManagementSettings"

          }

        },

        "ListItemAllFields": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/ListItemAllFields"

          }

        },

        "LockedByUser": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/LockedByUser"

          }

        },

        "ModifiedBy": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/ModifiedBy"

          }

        },

        "Properties": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/Properties"

          }

        },

        "VersionEvents": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/VersionEvents"

          }

        },

        "Versions": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv')/Versions"

          }

        },

        "CheckInComment": "",

        "CheckOutType": 2,

        "ContentTag": "{6CDC34BA-8E9A-4C01-9D6C-624FE0E64D39},4,1",

        "CustomizedPageStatus": 0,

        "ETag": "\"{6CDC34BA-8E9A-4C01-9D6C-624FE0E64D39},4\"",

        "Exists": true,

        "IrmEnabled": false,

        "Length": "380",

        "Level": 1,

        "LinkingUri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%202.csv?d=w6cdc34ba8e9a4c019d6c624fe0e64d39",

        "LinkingUrl": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/GSD Test Document Library/DS0001/Sample File 2.csv?d=w6cdc34ba8e9a4c019d6c624fe0e64d39",

        "MajorVersion": 3,

        "MinorVersion": 0,

        "Name": "Sample File 2.csv",

        "ServerRelativeUrl": "/sites/GSDRnD/GSD Test Document Library/DS0001/Sample File 2.csv",

        "TimeCreated": "2022-12-10T14:46:58Z",

        "TimeLastModified": "2022-12-10T14:50:31Z",

        "Title": null,

        "UIVersion": 1536,

        "UIVersionLabel": "3.0",

        "UniqueId": "6cdc34ba-8e9a-4c01-9d6c-624fe0e64d39"

      },

      {

        "__metadata": {

          "id": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD Test Document Library/DS0001/Sample File 3.docx')",

          "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')",

          "type": "SP.File"

        },

        "Author": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/Author"

          }

        },

        "CheckedOutByUser": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/CheckedOutByUser"

          }

        },

        "EffectiveInformationRightsManagementSettings": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/EffectiveInformationRightsManagementSettings"

          }

        },

        "InformationRightsManagementSettings": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/InformationRightsManagementSettings"

          }

        },

        "ListItemAllFields": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/ListItemAllFields"

          }

        },

        "LockedByUser": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/LockedByUser"

          }

        },

        "ModifiedBy": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/ModifiedBy"

          }

        },

        "Properties": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/Properties"

          }

        },

        "VersionEvents": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/VersionEvents"

          }

        },

        "Versions": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx')/Versions"

          }

        },

        "CheckInComment": "",

        "CheckOutType": 2,

        "ContentTag": "{E0CD7FBE-14A9-4471-A217-BB6D7E96D06C},7,10",

        "CustomizedPageStatus": 0,

        "ETag": "\"{E0CD7FBE-14A9-4471-A217-BB6D7E96D06C},7\"",

        "Exists": true,

        "IrmEnabled": false,

        "Length": "17413",

        "Level": 1,

        "LinkingUri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%203.docx?d=we0cd7fbe14a94471a217bb6d7e96d06c",

        "LinkingUrl": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/GSD Test Document Library/DS0001/Sample File 3.docx?d=we0cd7fbe14a94471a217bb6d7e96d06c",

        "MajorVersion": 4,

        "MinorVersion": 0,

        "Name": "Sample File 3.docx",

        "ServerRelativeUrl": "/sites/GSDRnD/GSD Test Document Library/DS0001/Sample File 3.docx",

        "TimeCreated": "2022-12-10T14:46:41Z",

        "TimeLastModified": "2022-12-24T17:23:02Z",

        "Title": "",

        "UIVersion": 2048,

        "UIVersionLabel": "4.0",

        "UniqueId": "e0cd7fbe-14a9-4471-a217-bb6d7e96d06c"

      },

      {

        "__metadata": {

          "id": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD Test Document Library/DS0001/Sample File 1.csv')",

          "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')",

          "type": "SP.File"

        },

        "Author": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/Author"

          }

        },

        "CheckedOutByUser": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/CheckedOutByUser"

          }

        },

        "EffectiveInformationRightsManagementSettings": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/EffectiveInformationRightsManagementSettings"

          }

        },

        "InformationRightsManagementSettings": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/InformationRightsManagementSettings"

          }

        },

        "ListItemAllFields": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/ListItemAllFields"

          }

        },

        "LockedByUser": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/LockedByUser"

          }

        },

        "ModifiedBy": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/ModifiedBy"

          }

        },

        "Properties": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/Properties"

          }

        },

        "VersionEvents": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/VersionEvents"

          }

        },

        "Versions": {

          "__deferred": {

            "uri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv')/Versions"

          }

        },

        "CheckInComment": "",

        "CheckOutType": 2,

        "ContentTag": "{10951643-66B8-4EE9-AB1C-D665D7AF0BF8},4,1",

        "CustomizedPageStatus": 0,

        "ETag": "\"{10951643-66B8-4EE9-AB1C-D665D7AF0BF8},4\"",

        "Exists": true,

        "IrmEnabled": false,

        "Length": "380",

        "Level": 1,

        "LinkingUri": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/GSD%20Test%20Document%20Library/DS0001/Sample%20File%201.csv?d=w1095164366b84ee9ab1cd665d7af0bf8",

        "LinkingUrl": "https://globalsharepoint2020.sharepoint.com/sites/GSDRnD/GSD Test Document Library/DS0001/Sample File 1.csv?d=w1095164366b84ee9ab1cd665d7af0bf8",

        "MajorVersion": 3,

        "MinorVersion": 0,

        "Name": "Sample File 1.csv",

        "ServerRelativeUrl": "/sites/GSDRnD/GSD Test Document Library/DS0001/Sample File 1.csv",

        "TimeCreated": "2022-12-10T14:46:58Z",

        "TimeLastModified": "2022-12-10T14:49:35Z",

        "Title": null,

        "UIVersion": 1536,

        "UIVersionLabel": "3.0",

        "UniqueId": "10951643-66b8-4ee9-ab1c-d665d7af0bf8"

      }

    ]

  }

}

List of file properties or metadata returns by GETFolderByServerRelativeUrl request REST API

  • CheckInComment
  • CheckOutType
  • ContentTag
  • CustomizedPageStatus
  • ETag
  • Exists
  • IrmEnabled
  • Length
  • Level
  • LinkingUri
  • LinkingUrl
  • MajorVersion
  • MinorVersion
  • Name
  • ServerRelativeUrl
  • TimeCreated
  • TimeLastModified
  • Title
  • UIVersion
  • UIVersionLabel
  • UniqueId

Advantages of REST API in Send an HTTP request to SharePoint with Power Automate

Below are the advantages of “Send an HTTP request to SharePoint:”

  • This is faster than the above methods.
  • We can include filter query string parameters.
  • The custom metadata columns are not returned by the REST API request GETFolderByServerRelativeUrl.

Key take-away:

From the above 3 methods, only Get Items or Get files (properties only) retrieve files along with all custom metadata; the List Folder and GETFolderByServerRelativeUrl request REST API methods don’t bring the custom metadata columns.

 

Summary: Get all files in a folder Power Automate

Thus, in this article, we have learned the following with respect to how to get all files in a folder using Power Automate:

  • Limit Entries to Folder in the Get Items query to get all files in a folder.
  • How to use the list folder query to list all files in a folder.
  • How to get all files in a folder using the “GETFolderByServerRelativeUrl” request REST API method

See Also: Power Automate Articles Hub (with real-time example)

If you like our articles, please appreciate our efforts by liking and sharing them with your friends and colleagues. Please join the mailing list to get our articles in your inbox as and when we publish them.

Happy automating and learning!

 

About Post Author

Do you have a better solution or question on this topic? Please leave a comment