Accessing the file name of a link inside a metadata field

I have files with metadata that looks like this

active :: yes
up :: [[company - Apple]]

I want to create a table that displays the text “Apple”, without the link and without the prefix "company - "

I’ve tried this:

TABLE WITHOUT ID file.link as element, replace(up, "company -", "") as company

WHERE active = "yes"

But replace fails:

No implementation of 'replace' found for arguments: link, string, string

This is probably due to up being a link object. Is there a way I can access the name of the note linked in up, as a string, so I can apply replace on it ?

Any other workarounds ?

Topic

Summary
  • How to get the filename of a link inside a metadata field?

Test

Summary
  • dataview: v0.5.55

Input

Summary

the related files

  • Location: “100_Project/02_dataview/Q88_Links/Q88_test_data/01”

  • filename : company - Apple
---
Date: 2000-01-01
---


  • filename : company - Coffee=>It does not exist.

dictionary files

  • Location: “100_Project/02_dataview/Q88_Links/Q88_test_data”

folder: 03

  • filename : dic_20000301
---
Date: 2000-03-01
---

active :: yes
up :: [[company - Apple]]

folder: 04

  • filename : dic_20000401
---
Date: 2000-04-01
---

active :: yes
up :: [[company - Coffee]]

folder: 06_null

  • filename : dic_20000601
---
Date: 2000-06-01
---

active :: yes
up :: 

folder: 07_string_excluded

  • filename : dic_20000701
---
Date: 2000-07-01
---

active :: yes
up :: tea

DQL10_get_the_filename_of_a_link_and_TABLE

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10_get_the_filename
_of_a_link
_and_TABLE
up:
a link
no 1.To filter by active
2.To filter by up
3.To define a field variable s_filename_of_link
4.To sort by file.link in ascending order
5.To display the result as a table
3.The prefix s before the field variable s_filename_of_link means that the data type of the variable is a String.

Q1: What does the following DQL statement mean?

Summary_Q
Original Example: Q1 (To be explained)
```dataview
FLATTEN regexreplace(meta(up).path, "^(.*/)(.+)(\.md)$", "$2") AS s_filename_of_link   
```

A1_11:

Another Example: A1_11

NOTE:To get the filename of a link

```dataview
// In English: 
// To define a field variable `s_filename_of_link` in each page as the expression like `regexreplace(meta(up).path, "^(.*/)(.+)(\.md)$", "$2")` by using `FLATTEN`
// 
// In other words:
// let page.s_filename_of_link = regexreplace(meta(up).path, "^(.*/)(.+)(\.md)$", "$2");
FLATTEN regexreplace(meta(up).path, "^(.*/)(.+)(\.md)$", "$2") AS s_filename_of_link   
```

DQL10_get_the_filename_of_a_link_and_TABLE

Summary_code
title: DQL10_get_the_filename_of_a_link_and_TABLE =>1.To filter by `active` 2.To filter by `up` 3.To define a field variable `s_filename_of_link` 4.To sort by file.link in ascending order 5.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      file.link AS "element",
      up AS "up",
      regexreplace(s_filename_of_link, "^company -", "") as "company"     

FROM "100_Project/02_dataview/Q88_Links/Q88_test_data"
WHERE active = "yes"

WHERE up != null
FLATTEN regexreplace(meta(up).path, "^(.*/)(.+)(\.md)$", "$2") AS s_filename_of_link
SORT file.link ASC

```

Screenshots(DQL10)


1 Like

Thanks for your reply @justdoitcc ! I had a bit of difficulty understanding it, but what I get is that I need to use the meta function on the link to access its properties:

TABLE WITHOUT ID 
	file.link as element,
	regexreplace(meta(up).path, "(.*/)company - (.*)\.md", "$2") as company
WHERE active = "yes"

In my case I don’t need the FLATTEN part, as the up field contains only 1 link

  • Your Regular Expression is very professional. Thanks for your reminder that there is a $2 in the RegExp. I almost forgot it.

  • I know that the up field contains only 1 link.

  • In addition to the original function you know, FLATTEN can also be used to define a field variable.

  • The following FLATTEN expressions are used to demonstrate how to define a field variable by using FLATTEN and how to use regexreplace step by step for beginners in order to write more complex DQL. Skilled at DQL, you could ignore them.

Explanations

Q: What does the following DQL statement mean?

FLATTEN regexreplace(meta(up).path, "^(.*/)(.+)(\.md)$", "$2") AS F_filename   

To get the filename of a link
  • In English: To define a field variable F_filename as the expression like regexreplace(meta(up).path, "^(.*/)(.+)(\.md)$", "$2") by using FLATTEN
  • In other words: let F_filename = regexreplace(meta(up).path, "^(.*/)(.+)(\.md)$", "$2");

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