maybe this helps
https://forum.posit.co/t/find-the-name-of-the-current-file-being-rendered-in-quarto/157756/2
from @cderv's answer :
knitr has
knitr::current_input()
function. This will return the filename of the input being knitted. You won't get the original filename because it gets processed by Quarto and an intermediate file is passed to knitr but it is just a matter for extension so this would give you the filename
please note that the name of the intermediate file has spaces and parentheses replaced with hyphens (-), so something like Ye Olde Filename (new) becomes Ye-Olde-Filename--new-