Is there a way to retrieve a list of tags of e.g. files in a folder?

Things I have tried

I have looked at the Templater and Dataview community plugins but not been able to do what I want.

What I’m trying to do

Aim

To retrieve a list of tags from specified files, e.g. in a folder, and insert them in files created from a template. Ideally this would be something that auto-updates when new tags are added.

Use case

I have a template file for an about/readme md file for each folder and, when it is created, I would like it to list all the tags from other files in that folder, either in the yaml section or as a list in the body of the note.

Thank you very much in advance for your help :slight_smile:

2 Likes

Scenario

  • Folder: Folder_A
  • Files in Folder_A:
  • readme/about file in Folder_A: readme_A

You can insert this query in your “readme_A” file:

```dataview
TABLE file.tags as tags
FROM "Folder_A"
WHERE file.name != this.file.name

This gives you a table/list of all the files in Folder_A, excluding the “readme_A” file (the expression WHERE file.name != this.file.name excludes the file where the query works - you can remove it if you want…).

Problem
file.tags is an “implicit field”, that is, a file metadata that gives you all the normal tags you create in the body of the note. To the tags created via YAML depends how you created them.

3 Likes

Hi @mnvwvnm , thank you for your reply. It’s been rather hectic so I have only just come back to this.
Thank you, your code gives me a table of all the files, except the current one, and all the tags in each file. I have tested it and it works with inline tags and with tags in the yaml, e.g. tags: [‘tag1’,tag2’].

Do you know of a way to list just the tags (no file names) and without duplicates?

Many thanks :slight_smile:

1 Like

typing “tag:” on the search bar on the left panel gives you a list of all your tags

1 Like

Hi @Walrux, thanks for the reply. I am looking to get a list of tags automatically in a note, e.g. using dataview. This is a useful tip though.

1 Like

Hi, I’m also interested in finding a solution for this. Having a page of showing all tags part of major tag A.

Quite often I’m using Obsidian on mobile and I would rather see the tags on a page, than to switch to the tag search option.

If you want a list of tags used on that note, you can use

`=this.file.tags`

For a general list/table of tags, separated from file name, without duplicates, I don’t know how to do that with dataview.

  1. If you want a list of all your tags on a note then the following command would do
    ```dataview
    table file.tags
    ```
  2. But if you want a list of, say, the notes containing #tag1, #tag2, #tag3 then you will have to use the following commands
    ```dataview
    table file.tags from #tag1 or #tag2 or #tag3
    ```

In the second method you will have to replace “or” with “and” if you want only those notes which has all the three tags . For example, let there be three notes- Note1, Note2, Note3. These notes have the following tags-
Note1 = #tag1, #tag2
Note2 = #tag1, #tag2
Note3 = #tag1, #tag2, #tag3

Now if you use from #tag1 and #tag3 then only Note3 will be displayed since it satisfies both the criterion, whereas if you use from #tag1 or #tag3 then all the three notes - Note1, Note2, and Note3-will be displayed since each note fulfills either of the criteria

The code snippet below will get all tags without duplicates and filenames in a certain folder. Notice that you should replace <path> with the path to the folder instead of the folder name only. :slight_smile:

```dataviewjs
let tags = []
for (let tag of dv.pages('<path>').file.tags) {
 if (tags.indexOf(tag) == -1) {
 tags.push(tag)
 }
}
dv.list(tags)
4 Likes

ha this is epic and exactly what i was searching for!

in a related query, whats the best way to export these results to a text file and get rid of the # (hash) sign? is there a programatic way to do this with the dataview js script?

i need to update this tag list often for other apps :smiley:

thx so much @Creling!

Z

How can I use dataview to list all files that share at least one tag with the current (active) file? I’ve played around with this.file.tags but without any meaningful result so far…

Edit: Found the solution - for anyone interested:

table file.folder
Where contains(file.tags, this.file.tags[0])
sort file.path

Or, if you just want a simple list:

list
Where contains(file.tags, this.file.tags[0])
2 Likes

Thanks for your solution!

It works, so I simplified it with

dv.list(new Set(dv.pages().file.tags))
1 Like

Nice!

Is there a way to exclude tags?

For example, say my tags are as the PARA method:
1 project
2 area
3 resources
4 archive

Would it be possible to only show all tags of 2 and 3?

the “dv.” code is the javascript version, if you stick to the basic dataview code instead, like at the top, you can easily add exclusions with “and” statements tacked onto the WHERE line.

This code is an unrelated query for file sizes but you can see the tag exclusion and the path exclusions I added.

```dataview
LIST
from “”
where length(file.inlinks) =0 and length(file.outlinks) = 0 and file.folder != “4. ARCHIVE” and file.folder != “4. ARCHIVE/TEMPLATES” and !contains(file.tags, “#io”) and file.folder != “001 DAILY” and file.folder != “001 DAILY/PAST”
```

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