Windows Script Host之用vbs实现[浏览文件夹]功能
程序员文章站
2022-04-10 08:07:45
'************************************************ ' file:dialog.vbs (wsh&nbs...
'************************************************
' file:dialog.vbs (wsh sample in vbscript)
' author:(c) g. born
'
' using the shell dialog box to select a folder
'************************************************
option explicit
' flags for the options parameter
const bif_returnonlyfsdirs = &h0001
const bif_dontgobelowdomain= &h0002
const bif_statustext = &h0004
const bif_returnfsancestors= &h0008
const bif_editbox= &h0010
const bif_validate = &h0020
const bif_browseforcomputer= &h1000
const bif_browseforprinter = &h2000
const bif_browseincludefiles = &h4000
dim wsh, objdlg, objf
' get application object of the windows shell.
set objdlg = wscript.createobject("shell.application")
' use the browseforfolder method.
' for instance: set objf = objdlg.browseforfolder _
' (&h0, "select the folder to copy", &h10, "c:\born")
set objf = objdlg.browseforfolder (&h0, _
"select the folder to copy", _
bif_editbox + bif_returnonlyfsdirs)
' here we use the first method to detect the result.
if isvalue(objf) then
msgbox "selected folder: " & objf.title
else
msgbox "canceled"
end if
' here we use typename to detect the result.
if instr(1, typename(objf), "folder") > 0 then
msgbox "selected folder: " & objf.title
else
msgbox "canceled"
end if
function isvalue(obj)
' check whether the value has been returned.
dim tmp
on error resume next
tmp = " " & obj
if err <> 0 then
isvalue = false
else
isvalue = true
end if
on error goto 0
end function
'*** end
' file:dialog.vbs (wsh sample in vbscript)
' author:(c) g. born
'
' using the shell dialog box to select a folder
'************************************************
option explicit
' flags for the options parameter
const bif_returnonlyfsdirs = &h0001
const bif_dontgobelowdomain= &h0002
const bif_statustext = &h0004
const bif_returnfsancestors= &h0008
const bif_editbox= &h0010
const bif_validate = &h0020
const bif_browseforcomputer= &h1000
const bif_browseforprinter = &h2000
const bif_browseincludefiles = &h4000
dim wsh, objdlg, objf
' get application object of the windows shell.
set objdlg = wscript.createobject("shell.application")
' use the browseforfolder method.
' for instance: set objf = objdlg.browseforfolder _
' (&h0, "select the folder to copy", &h10, "c:\born")
set objf = objdlg.browseforfolder (&h0, _
"select the folder to copy", _
bif_editbox + bif_returnonlyfsdirs)
' here we use the first method to detect the result.
if isvalue(objf) then
msgbox "selected folder: " & objf.title
else
msgbox "canceled"
end if
' here we use typename to detect the result.
if instr(1, typename(objf), "folder") > 0 then
msgbox "selected folder: " & objf.title
else
msgbox "canceled"
end if
function isvalue(obj)
' check whether the value has been returned.
dim tmp
on error resume next
tmp = " " & obj
if err <> 0 then
isvalue = false
else
isvalue = true
end if
on error goto 0
end function
'*** end
下一篇: 用vbs检查注册表项的访问权限的代码