问题描述
我很困惑 - 我一直在谷歌上搜索了一个小时,并试图大概十个不同的形式设置posixDirectory为((路径å文件)作为字符串的母公司)的POSIX路径
,但我似乎无法得到它的权利。
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 doingset 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((å文件的母公司))
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
或用贝壳
or using shell
set thePath to "/Users/USERNAME/Documents/Test/selectedTextColour.css"
set parentPath to do shell script "dirname " & quoted form of thePath
结果:/用户/用户名/文档/测试
从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:用户:用户名:文件:测试
这篇关于获取输入文件的目录(AppleScript的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!