gpt4 book ai didi

applescript - 获取输入文件的目录(Applescript)

转载 作者:行者123 更新时间:2023-12-01 07:02:14 29 4
gpt4 key购买 nike

我很困惑 - 我已经用谷歌搜索了一个小时,并尝试了大约十种不同形式的 set posixDirectory to POSIX path of (parent of (path to aFile) as string)但我似乎无法正确理解。

我通过执行获得完整的 POSIX 路径(包括文件名)set posixFilePath to POSIX path of aFile
现在,我如何获得目录的 POSIX 路径?根据我的工作,我收到了各种错误......无法制作别名......无法获得别名的父级......

我认为这应该有效,但它不是......
set posixDirectory to POSIX path of ((parent of aFile))

最佳答案

如果您已经有了初始路径,有几种方法可以做到这一点。

从 Posix 路径格式

set thePath to "/Users/USERNAME/Documents/Test/selectedTextColour.css"


set textNumber1 to characters 1 thru -((offset of "/" in (reverse of items of thePath as string)) + 1) of thePath as string

或使用 shell
set thePath to "/Users/USERNAME/Documents/Test/selectedTextColour.css"


set parentPath to do shell script "dirname " & quoted form of thePath

结果: "/Users/USERNAME/Documents/Test"
从 Posix 文件格式
set thePath to "Macintosh HD:Users:USERNAME:Documents:Test:selectedTextColour.css"


set textNumber1 to characters 1 thru -((offset of ":" in (reverse of items of thePath as string)) + 1) of thePath as string

结果: "Macintosh HD:Users:USERNAME:Documents:Test"

关于applescript - 获取输入文件的目录(Applescript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30823900/

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