Dataview: Table showing only enclosing folder

I am trying to build a table using DataView based on a projects folder which has sub-folders for different projects. Each note has a status entry in the frontmatter and I’d like to include the folder name as an easy way of seeing which project a note is part of, but if I include file.folder, it gives me the who path. Is there a way to have it show only the name of the folder under which the note is filed?

Currently I have:

TABLE file.folder, status FROM "Projects" 

The works, but gives me the entire path, e.g. Projects/Server 2012 Replacements when I’d just like everything after the last slash.

Thoughts?

Given that your query runs from within the main project folder, then maybe something like one of the following could work:


```dataview
TABLE WITHOUT ID link(file.link, projectFileName) as "Project file"
FLATTEN replace(replace(file.path, this.file.folder + "/", ""), ".md", "") as projectFileName
WHERE startswith(file.folder, this.file.folder)
```

Or

```dataview
TABLE WITHOUT ID link(file.link, projectFileName) as "Project file"
FLATTEN regexreplace(file.path, this.file.folder + "/(.*).md", "$1") as projectFileName
WHERE startswith(file.folder, this.file.folder)
``` 

Or similar variants using file.folder as the base for the replace.

These don’t counter for any notes having a status field, so you’ll need to massage them to match your use case, but it shows one possible way to remove a leading part of the file path or folder to indicate the sub folders.

Similar approaches could be used to remove a fixed portion of any file path or folder. E.g. if you had one of your projects file named /Projects/MyGeniousSubprojects/MyUltimateIdea.md, you could use something like regexreplace(file.path, "/Projects/(.*)/[^/]+\.md", "$1") as projectName to extract just the project name (with potential sub-folders).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.