如何使用重命名文件在Lisp中移动文件 [英] How to move a file in Lisp using rename-file
本文介绍了如何使用重命名文件在Lisp中移动文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Lisp中以与实现无关的方式移动文件的最佳方法是什么?例如,我有一个图像文件:
What's the best way to move a file in Lisp in an implementation-independent way? For example I have an image file:
(setq oldpath #P"SERVER:PICTURES;TEMP;PHOTO.PNG")
,我想将其从TEMP目录移至PICTURES目录.这似乎可行:
and I want to move it out of the TEMP directory into the PICTURES directory. This seems to work:
(setq newpath
(make-pathname
:host (pathname-host oldpath)
:directory (butlast (pathname-directory oldpath))
:name (pathname-name oldpath)
:type (pathname-type oldpath)))
(rename-file oldpath newpath)
但是还有更优雅的方式吗?
but is there a more elegant way?
谢谢大卫
推荐答案
我通常在使用:
(make-pathname :defaults old-path
:directory (butlast (pathname-directory oldpath)))
:defaults
参数可确保将旧路径名的所有相关部分都复制过来.
The :defaults
argument makes sure that all relevant parts of the old pathname are being copied over.
这篇关于如何使用重命名文件在Lisp中移动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文