文件的存在AppleScript的测试 [英] Applescript testing for file existence
本文介绍了文件的存在AppleScript的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,我认为这将是一个简单的,但显然我失去了一些东西明显。我的code是如下:
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屋!
查看全文