为什么会出错,VBS判断文件是否存在

bl("D:\Temp\vjc\退避\")
function bl(s)
set f=createobject("scripting.filesystemobject")
for each i in f.getfolder(s).files
if i.name="vjc2.log" then
msgbox "vjc2.log 存在! 点 确定 退出脚本"
else
wscript.Sleep 5000
msgbox 1
end if
msgbox 2
next
for each ii in f.getfolder(s).subfolders
bl(s)
next
end function

第1个回答  2012-06-03
set fso=createobject("scripting.filesystemobject")
'-----------------------------
public function dir(byval exist)
if fso.folderexists(exist&"\") then
if fso.folderexists(exist) then dir=fso.getfolder(exist) else dir=""
else
if fso.fileexists(exist) then dir=fso.getfile(exist) else dir=""
end if
end function
'判断文件(夹)是否存在
'-----------------------------

给你一个判断文件(夹)存在的函数
不需要遍历截取文件.本身就有fileexists这个函数能立即对文件夹里的文件(夹)进行获取.
有了以上函数就不需要遍历文件了.只需遍历文件夹就轻松获取了.

使用方法:
if dir(文件)<>"" then
存在
else
不存在
end if

相关了解……

你可能感兴趣的内容

大家正在搜

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网