Here is a small bit of code to extract the last folder from the specified folder.
Code:
(defun lastfolder (path /)
(setq folder (substr path 1 (1- (strlen path))))
(while (vl-string-search (chr 47) folder)
(setq folder (vl-string-subst (chr 92) (chr 47) folder))
)
(setq folder (substr folder (+ 2 (vl-string-position 92 folder 2 T))))
)
You will need to save this function to a file with a .lsp extension. You may even save it within your ACADDOC.LSP file if you have one. If you do not have one you could create it within a folder that is listed in your support path folder list.
You would then call this function in this fashion.
Code:
(lastfolder foldername)
Replace the foldername above with your desired folder. Remember to place the name within quotes (").
To get the folder the drawing is located in, use the following.
Code:
(lastfolder (getvar "dwgprefix"))
Your original request did not specify how you would actually use this. If you could elaborate a bit, someone here may be able to help you a little bit more.