获取输入文件的目录(Applescript) [英] Getting directory of input file (Applescript)

查看:19
本文介绍了获取输入文件的目录(Applescript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm confused - I've been googling for an hour and have tried probably ten different forms of set posixDirectory to POSIX path of (parent of (path to aFile) as string) but I can't seem to get it right.

我通过执行获得完整的 POSIX 路径(包括文件名)设置posixFilePath为文件的POSIX路径

I'm getting the full POSIX path (including the filename) by doing set posixFilePath to POSIX path of aFile

现在,我如何获得目录的 POSIX 路径?根据我的操作,我收到各种错误...无法创建别名...无法获取别名的父项...

Now, how do I get the POSIX path of just the directory?? I'm getting various errors depending on what I do... can't make alias.. can't get parent of alias...

我认为这应该有效,但它不是......将posixDirectory设置为((aFile的父级))的POSIX路径

I would think this should work but it's not... set posixDirectory to POSIX path of ((parent of aFile))

推荐答案

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

There are couple of ways to do this if you already have the initial path.

来自 Posix 路径格式

From Posix path format

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


or using 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 文件格式

From Posix file format

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆