Can't you just construct the name the way you looked it up?
So if you are in /base, and you got file.txt in a directory listing of path/to/a/, your path is /base/path/to/a/file.txt.
If you are wanting to use the actual path used to set the current directory to /base, you might want to check $PWD instead of cwd().