4

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

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

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

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

4

2 回答 2

9

如果你需要一些与你的主目录相关的东西,Common Lisp 函数user-homedir-pathnamemerge-pathnames可以帮助你:

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

名称字符串函数(例如,名称字符串目录名称字符串)按预期在此路径名上工作:

CL-USER> (directory-namestring
          (merge-pathnames 
           (make-pathname
            :directory '(:relative "directoryyouwant"))
           (user-homedir-pathname)))
"/home/username/directoryyouwant/"
于 2013-05-20T19:03:46.487 回答
4
CL-USER > (make-pathname :directory (append (pathname-directory
                                              (user-homedir-pathname))
                                            (list "directoryiwant"))
                         :defaults (user-homedir-pathname))

#P"/Users/joswig/directoryiwant/"

该函数NAMESTRING将其作为字符串返回。

CL-USER > (namestring #P"/Users/joswig/directoryiwant/")
"/Users/joswig/directoryiwant/"
于 2013-05-20T19:47:14.707 回答