Path Applescript检查网络中是否存在文件,路径带有变量

Path Applescript检查网络中是否存在文件,路径带有变量,path,applescript,Path,Applescript,我正在尝试检查网络上的文件夹中是否存在文件。 当我像第二个示例中那样硬编码路径时,脚本的工作方式与预期的一样 但是,在第一个示例中,脚本无法正常工作。我相信我引用的变量正确地用and分隔了字符串和变量,并且确保最后一个变量被转换为字符串 tell application "Finder" set a to "video1" set thefile to ("/Volumes/folder/" & a & ".avi") if exists POSIX

我正在尝试检查网络上的文件夹中是否存在文件。 当我像第二个示例中那样硬编码路径时,脚本的工作方式与预期的一样

但是,在第一个示例中,脚本无法正常工作。我相信我引用的变量正确地用and分隔了字符串和变量,并且确保最后一个变量被转换为字符串

  tell application "Finder"
    set a to "video1"
    set thefile to ("/Volumes/folder/" & a & ".avi")
    if exists POSIX file (thefile as string) then
        log "True"
    else
        log "False"
    end if
end tell

tell application "Finder"
    if exists POSIX file ("/Volumes/folder/video1.avi") then
        log "True"
    else
        log "False"
    end if
end tell

有没有办法解决这个问题?

有一个更方便的办法

Finder将本地卷和网络卷都视为磁盘。磁盘的名称是卷之后的路径组件

不过,我建议您更喜欢系统事件,它更优化,并且还有一个磁盘元素

set a to "video1"
set thefile to a & ".avi"
tell application "System Events"
   if exists file thefile of disk "folder" then
      log "True"
   else
      log "False"
   end if
end tell