Applescript 测试文件是否存在 [英] Applescript testing for file existence
本文介绍了Applescript 测试文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,我以为这会很简单,但显然我遗漏了一些明显的东西.我的代码如下:
OK, I thought this would be a simple one, but apparently I'm missing something obvious. My code is as follows:
set fileTarget to ((path to desktop folder) & "file$") as string
if file fileTarget exists then
display dialog "it exists"
else
display dialog "it does not exist"
end if
容易吧?不幸的是,当我运行脚本时,它返回错误
Easy right? Unfortunately, when I run the script it returns the error
Can’t get file "OS X:Users:user:Desktop:files$".
文件是否存在并不重要,这与我得到的错误相同.我尝试了十几种不同的方法,但它仍然难倒我.
It doesn't matter if the file exists or not, this is the same error I get. I've tried a dozen different things but it still stumps me.
推荐答案
我使用这个子程序来查看文件是否存在:
I use this subroutine to see if a file exists or not:
on FileExists(theFile) -- (String) as Boolean
tell application "System Events"
if exists file theFile then
return true
else
return false
end if
end tell
end FileExists
加盐调味.
这篇关于Applescript 测试文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文