要在AppleScript中获取不带扩展名的文件名,可以使用以下方法:
set filePath to "/path/to/your/file.ext"
set fileNameWithExtension to name of (info for (POSIX file filePath))
set fileNameWithoutExtension to text 1 thru -2 of fileNameWithExtension -- 去掉最后一个字符(点号和扩展名)
display dialog fileNameWithoutExtension
这里是脚本的解释:
set filePath to
:设定文件路径变量。file
:创建一个file
对象。POSIX file
:将文件路径转换为POSIX路径格式(Mac系统下)。name of (info for ...)
:获取文件的名称,包括扩展名。text 1 thru -2 of fileNameWithExtension
:获取文件名(不包括扩展名)。这里的-2
表示从字符串末尾往前数第二个字符。这样我们就得到了不带扩展名的文件名。请将/path/to/your/file.ext
替换为您想要获取文件名的实际文件路径。运行此脚本后,会弹出一个对话框显示不带扩展名的文件名。
领取专属 10元无门槛券
手把手带您无忧上云