0

I'm trying to create a spreadsheet with a list of all the folders and sub-folders in a SharePoint Site. I used this solution here: Get complete subfolder-structure from library/folder and was able to get it to work - mostly.

I've been testing this on a smaller SharePoint site with only 2 layers of subfolders to ensure it's working properly before implementing on my massive SharePoint site. The problem I'm running into is that the folder titles are coming up as "null" values and the Server Relative URL for each folder also doesn't include the name of the folders/sub-folders.

What it should be producing, is the following:

Title="Test Folder A"; Server Relative URL="sites/SiteName/Document Library"

Title="Test Folder B"; Server Relative URL="sites/SiteName/Document Library"

Title="Test Folder C"; Server Relative URL="sites/SiteName/Document Library/Test Folder A"

But what it's producing is:

Title=null; Server Relative URL="sites/SiteName/Document Library"

Title=null; Server Relative URL="sites/SiteName/Document Library"

Title=null; Server Relative URL="sites/SiteName/Document Library/Test Folder A"

So I know that the code is properly looping through all the folders and sub-folders, but I'm not able to properly retrieve or display that data as I'm looping through. When I look at the outputs from the Send an HTTP request to SharePoint action, it's also showing these null values for Title.

I tried running the script again but for a different document library in the same site and I was able to get the FIRST folder name to appear, but the rest came up null:

Title="Test Folder A"; Server Relative URL="sites/SiteName/Document Library B"

Title=null; Server Relative URL="sites/SiteName/Document Library B"

Title=null; Server Relative URL="sites/SiteName/Document Library B/Test Folder A"

My automation has the same steps as the solution linked above. Any thoughts on what I'm doing wrong or anything that I'm missing?

Step 1 of my automation

Steps 2 and 3 of my automation

Step 4 of my automation

Current outputs:

Select action outputs

Create CSV table outputs

EDIT/UPTDATE TO QUESTION: Per the recommended solution from @jleture I was able to get the flow to run with $filterFSObjectType eq 0 (not $filter=FSObjectType eq 0 with the equal sign; and I've found that using %20 or a space doesn't change the results). However, the flow is still pulling all files, not just folders, into the results list. Here is my updated Uri on the HTTP request:
_api/web/lists/getbytitle('Training Materials Library')/items?$select=Title,FileLeafRef,FileDirRef&$filterFSObjectType eq 0

I assumed it's unable to filter by file type because it's not listed in the URI and tried adding in FSObjectType into the inquiry: _api/web/lists/getbytitle('Training Materials Library')/items?$select=Title,FileLeafRef,FileDirRef,FSObjectType&$filterFSObjectType eq 0
This gives me an error:
{"odata.error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The field or property 'FSObjectType' does not exist."}}}
clientRequestId: 0974a93a-c535-4a1f-9739-bbfa52a6e44e
serviceRequestId: a6ee6aa1-b0e2-7000-2ab4-d6e5af5cd936

I've also tried just Type and ObjectType with no luck. Am I on the right path? Or is there another reason why it's not able to filter out files and just pull folder names?

    1 Answer 1

    0

    Folder does not have a Title property. Insted, use FileLeafRef.

    Considering a SharePoint document library Documents with a folder F1, you can get the value of the folder F1 with this query:

    https://your-tenant.sharepoint.com/sites/your-site/_api/web/lists/getbytitle('Documents')/items?$select=Title,FileLeafRef,FileDirRef&$filter=FSObjectType%20eq%200 

    Note: $filter=FSObjectType eq 0 will target only folders.

    Result:

    { "d": { "results": [ { "FileDirRef": "/sites/your-site/Documents", "FileLeafRef": "F1", "Title": null } ] } } 
    5
    • Yes! Thank you, this worked! Only now it's not filtering for folders and instead producing a list of all files and folders in the Library. I thought the filterFSObjectType%20eq%201 would take care of that?CommentedDec 2, 2024 at 15:29
    • Yes, there was an error in my query &$filter=FSObjectType%20eq%201 (with =) and not &$filterFSObjectType%20eq%201
      – jleture
      CommentedDec 2, 2024 at 16:11
    • Thank you. I tried it this way as well and I'm still getting all files, including .docx, mp4, .clipchamp, and .webmCommentedDec 4, 2024 at 20:22
    • I just looked at the outputs from the HTTP Request action and I think the problem is that it's not pulling file type as a property? This is what I'm seeing for each entry: { "FileLeafRef": "How to Share Files.mp4", "Title": null, "FileDirRef": "/sites/TechLearningCenter/Demo Doc Library/Videos by Training Topic" },CommentedDec 4, 2024 at 20:24
    • $filter=FSObjectType eq 0 will target only folders. A file will have FSObjectType 1. I copy/paste your original filter with 1 by mistake.
      – jleture
      CommentedDec 5, 2024 at 8:59

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.