中经国际 中国金融租赁:FSO删除问题

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/30 12:30:14
我的FSO删除路径是根据数据库里的路径进行删除的.当文件存在时可以实现删除并顺利运行,但当文件不存在时,就会出错.像是网页无法删除的那种.
我的程序是这样的
name值是路径的变量

FiLePaTh = Server.MapPath(".")& "\" & name
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(filepath)
Set fso = nothing

应如何修改,发现此文件不存在时,跳过FSO删除.谢谢.
on error resume next并不是万能,用on error resume next即使用错误存在也很难发现...

不知道各位还有没有更好的解决方法.

FiLePaTh = Server.MapPath(".")& "\" & name

Set fso = CreateObject("Scripting.FileSystemObject")

if fso.Fileexists(filepath) then
fso.DeleteFile(filepath)
end if

Set fso = nothing

两种方法都可以,第二种方法更正规,第一种方法的优势是代码量少,如何取舍,看你的了
我一般会选择后一种

我也不太清楚,你在你的代码中加入这句话,应该可以解决你当前问题

on error resume next

可以忽略错误,试试