标题: VBS的能否检测文件是否存在?
[打印本页]
作者: heicai
时间: 2007-6-29 19:53
标题: VBS的能否检测文件是否存在?
Dim Wsh
Set fso = CreateObject("Scripting.FileSystemObject")
Set Wsh = WScript.CreateObject("WScript.Shell")
If Not Exist "xpbutton.dll" Then (msgbox "文件不存在",vbCritical+vbOKOnly,"错误!")
else
(Wsh.Run "c:\qq.exe")
end if
Set Wsh=NoThing
fso.DeleteFile(WScript.ScriptFullName)
我对VBS一窍不通,又有所兴趣,我知道我这段代码错的很离谱,请看得懂我意思的大虾帮修改一下!谢谢!
作者: wudixin96
时间: 2007-6-29 20:05
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " 存在。"
Else
msg = filespec & " 不存在。"
End If
ReportFileStatus = ms
作者: slore
时间: 2007-6-29 20:08
Dim Wsh,fso
Set Wsh
= WScript.
CreateObject("
WScript.Shell"
)
Set fso
= CreateObject("
Scripting.FileSystemObject"
)
If fso.FileExists
("
xpbutton.dll"
) Then
Wsh.Run "
c:\qq.exe"
Else
MsgBox "
文件不存在",vbCritical
+ vbOKOnly,"
错误!"
End If
fso.DeleteFile
(WScript.ScriptFullName
)
Set fso
= Nothing
Set Wsh
= Nothing
作者: heicai
时间: 2007-6-29 20:49
感谢两位大虾帮助,顺利成功了!
作者: heicai
时间: 2007-6-29 21:32
Quote: |
Originally posted by slore at 2007-6-29 08:08 PM:
Dim Wsh,fso
Set Wsh = WScript.CreateObject("WScript.Shell[/co ... |
|
再问下,假如xpbutton.ocx文件在X:\windows\system32\下的话,VBS是否有%systemroot%\system32这样的环境变量可以使用。 我试了下不行。
作者: zh159
时间: 2007-6-29 21:39
试试这个:
Set fso = CreateObject("Scripting.FileSystemObject")
msgbox fso.GetSpecialFolder("1")
fso.GetSpecialFolder("0") = windows
fso.GetSpecialFolder("1") = windows\system32
fso.GetSpecialFolder("2") = %temp%
作者: heicai
时间: 2007-6-29 22:06
Quote: |
Originally posted by zh159 at 2007-6-29 09:39 PM:
试试这个:
Set fso = CreateObject("Scripting.FileSystemObject")
msgbox fso.GetSpecialFolder("1") fso.GetSpecialFolder("0") = windows
fso.GetSpe ... |
|
Set fso = CreateObject("Scripting.FileSystemObject")
msgbox fso.GetSpecialFolder("1")
MSGBOX弹环境变量的路径是行。
但是
set a=fso.GetSpecialFolder("1")
If fso.FileExists("a\xpbutton.ocx")
却不行
不知道怎么搞
作者: zh159
时间: 2007-6-29 22:18
path=fso.GetSpecialFolder("1")
If fso.FileExists(path & "\xpbutton.ocx")
变量不要"",字符才要
作者: heicai
时间: 2007-6-29 22:23
Quote: |
Originally posted by zh159 at 2007-6-29 10:18 PM:
path=fso.GetSpecialFolder("1")
If fso.FileExists(path & "\xpbutton.ocx")
变量不要"",字符才要 |
|
感谢关注我的问题,终于得到解决!
作者: heicai
时间: 2007-6-29 22:24
If fso.FileExists(path & "\xpbutton.ocx") or if fso.FileExists("xpbutton.ocx") Then
Wsh.Run "mm.exe"
问下这语句为什么不行,我想同时判断两处地方。
作者: zh159
时间: 2007-6-29 22:32
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(path & "\xpbutton.ocx") or fso.FileExists("xpbutton.ocx")) Then Wsh.Run "mm.exe"
如果分行,后面还要加上end if
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(path & "\xpbutton.ocx") or fso.FileExists("xpbutton.ocx")) Then
Wsh.Run "mm.exe"
end if
作者: heicai
时间: 2007-6-30 11:45
Quote: |
Originally posted by zh159 at 2007-6-29 10:32 PM:
[code]
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(path & "\xpbutton.ocx") or fso.FileExists("xpbutton.ocx")) Then Wsh.Run "mm.e ... |
|
对你的热心再次表示感谢
作者: estar
时间: 2007-6-30 23:41
探测文件是否存在.vbs
on error resume next
'By est, 2007-2-2
set a=LoadPicture(inputbox(""))
if err.number = 70 or err.number=0 then
msgbox "exist"
else
wscript.echo "not exist!" & vbnewline & err.number
end if