我希望能够将任何操作系统上主目录中的某个目录转换为该操作系统上的实际绝对路径,例如(make-pathname :directory '(:absolute :home "directoryiwant") 应该在 unixlike 系统上转换为“/home/weirdusername/directoryiwant”。

选择这样做的功能是什么?作为

(directory-namestring
      (make-pathname :directory '(:absolute :home "directoryiwant"))
> "~/"

实际上并没有做这笔交易。

最佳答案

如果您需要与主目录相关的内容,Common Lisp 函数 user-homedir-pathnamemerge-pathnames 可以帮助您:

CL-USER> (merge-pathnames
          (make-pathname
           :directory '(:relative "directoryyouwant"))
          (user-homedir-pathname))
#P"/home/username/directoryyouwant/"

namestring functions (例如, 名称字符串 目录名称字符串 )按预期在此路径名上工作:
CL-USER> (directory-namestring
          (merge-pathnames
           (make-pathname
            :directory '(:relative "directoryyouwant"))
           (user-homedir-pathname)))
"/home/username/directoryyouwant/"

关于directory - 如何翻译 (make-pathname :directory '(:absolute :home "directoryiwant") into absolute path,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16656079/

10-11 23:40