gpt4 book ai didi

directory - 如何翻译 (make-pathname :directory '(:absolute :home "directoryiwant") into absolute path

转载 作者:行者123 更新时间:2023-12-04 22:32:38 28 4
gpt4 key购买 nike

我希望能够将任何操作系统上主目录中的某个目录转换为该操作系统上的实际绝对路径,例如(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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com