Kri*_*ell 1 file-io lotusscript
这似乎是最基本的东西.谷歌上有很多例子,所有这些都放在我的代码中并得到了相同的结果.
我相信我错过了语言特有的东西,而且真的很烦人.
特定
pathName$ = "..\..\images\" + artID + "\" + artNum + "\"
dirTest$ = "..\..\images\" + artID + "\"
If Dir$(pathName$ , ATTR_DIRECTORY) = "" Then
MsgBox "No Dir"
Else
MsgBox "Dir Found!"
End If
Run Code Online (Sandbox Code Playgroud)
(everthing正确调暗)
我把msgbox放在pathName $之前,就在DIR调用之前,但它在测试时失败了.我知道dir在某些情况下不存在的事实,但我想捕获错误,没有脚本崩溃未能找到目录.
我DIR (path,16) DIR$(path,16) DIR (path$,16) DIR$(path$,16)和ATTR_DIRECTORY关键词一样尝试过.
如何在Lotusscript中优雅地检查目录的存在?
如果目录不存在,Dir $命令将生成运行时错误代码76.因此,您可以通过添加On Error 76 Resume Next到代码来捕获运行时错误:
pathName$ = "..\..\images\" + artID + "\" + artNum + "\"
dirTest$ = "..\..\images\" + artID + "\"
On Error 76 Resume Next
If Dir$(pathName$ , ATTR_DIRECTORY) = "" Then
MsgBox "No Dir"
Else
MsgBox "Dir Found!"
End If
Run Code Online (Sandbox Code Playgroud)
灵感:http://searchdomino.techtarget.com/tip/Finding-files-and-directories-with-LotusScript