g.fullPath is a really good method.
4726839) eliminates several faux-helper methods and several kwargs. I am going to continue eliminating kwargs in leoAtFile.py.I could wish that it would return a directory instead of None when the path is to a directory instead of a file, but I suppose that would break some things that use it. It could have a new returnDir=False argument, so that nothing downstream get broken.
g.fullPath is a really good method.
If you don't care whether there is an @<file node> in p or p's ancestors, you could do something like this:aList = g.get_directives_dict_list(p)
path = c.scanAtPathDirectives(aList)
c.scanAtPathDirective handles many details like expanding user expressions and "~". This might be simpler than your script.