vbs選擇文件夾效果代碼
更新時(shí)間:2008年08月01日 23:26:57 作者:
非常不錯(cuò)的用vbs實(shí)現(xiàn)選擇文件夾方法
不用組件的話有兩種辦法:
set objFile = CreateObject("SAFRCFileDlg.FileOpen")
Set objShell = CreateObject("Shell.Application")
本blog里都有示例。
如果調(diào)用vb組件,可以是:
flag = &h200
whichone = OpenFile("Choose a File!", "C:\", "Everything|*.*|TextFiles|*.TXT|Word-Documents|*.DOC", 2, flag)
MsgBox "Raw data returned: " & whichone
' Split up multi selection result:
' space is used as separator:
whichone = Split(whichone, " ")
' field index 0 contains path information:
path = whichone(0)
' list all the files:
' how many files were selected?
filecount = UBound(whichone)
if filecount=0 then
' just one file selected!
MsgBox "You selected one file: " & whichone(0)
' check status of Read Only checkbox
' is bit 1 set or cleared?
' works only if just one file was selected!
MsgBox "Returned flag: " & flag
if (flag and 1) then
' (flag and 1)<>0, transforms to true
' bit is set!
MsgBox "ReadOnly selected!"
else
MsgBox "ReadOnly not selected!"
end If
' check whether selected file is of default type (txt)
if (flag and 1024) then
MsgBox "selected file is no txt file!"
else
MsgBox "selected file is of default type!"
end if
else
' more than one file selected!
MsgBox "You selected " & filecount & " files!"
for x = 1 to UBound(whichone)
list = list & path & whichone(x) & vbCr
next
MsgBox list
end If
function OpenFile(title, dir, filter, index, flags)
set comdlg = CreateObject("MSComDlg.CommonDialog")
comdlg.filter = filter
comdlg.FilterIndex = index
comdlg.Flags = flags
comdlg.MaxFileSize = 260
comdlg.CancelError = false
comdlg.DialogTitle = title
comdlg.InitDir = dir
' set txt as default
comdlg.DefaultExt = "txt"
comdlg.ShowOpen
OpenFile = comdlg.filename
' important: return flag status so your main script can
' check it:
flags = comdlg.Flags
end function
組件相關(guān)文件下載 http://xiazai.jb51.net/jbtools/vb6controls.rar
set objFile = CreateObject("SAFRCFileDlg.FileOpen")
Set objShell = CreateObject("Shell.Application")
本blog里都有示例。
如果調(diào)用vb組件,可以是:
flag = &h200
whichone = OpenFile("Choose a File!", "C:\", "Everything|*.*|TextFiles|*.TXT|Word-Documents|*.DOC", 2, flag)
MsgBox "Raw data returned: " & whichone
' Split up multi selection result:
' space is used as separator:
whichone = Split(whichone, " ")
' field index 0 contains path information:
path = whichone(0)
' list all the files:
' how many files were selected?
filecount = UBound(whichone)
if filecount=0 then
' just one file selected!
MsgBox "You selected one file: " & whichone(0)
' check status of Read Only checkbox
' is bit 1 set or cleared?
' works only if just one file was selected!
MsgBox "Returned flag: " & flag
if (flag and 1) then
' (flag and 1)<>0, transforms to true
' bit is set!
MsgBox "ReadOnly selected!"
else
MsgBox "ReadOnly not selected!"
end If
' check whether selected file is of default type (txt)
if (flag and 1024) then
MsgBox "selected file is no txt file!"
else
MsgBox "selected file is of default type!"
end if
else
' more than one file selected!
MsgBox "You selected " & filecount & " files!"
for x = 1 to UBound(whichone)
list = list & path & whichone(x) & vbCr
next
MsgBox list
end If
function OpenFile(title, dir, filter, index, flags)
set comdlg = CreateObject("MSComDlg.CommonDialog")
comdlg.filter = filter
comdlg.FilterIndex = index
comdlg.Flags = flags
comdlg.MaxFileSize = 260
comdlg.CancelError = false
comdlg.DialogTitle = title
comdlg.InitDir = dir
' set txt as default
comdlg.DefaultExt = "txt"
comdlg.ShowOpen
OpenFile = comdlg.filename
' important: return flag status so your main script can
' check it:
flags = comdlg.Flags
end function
組件相關(guān)文件下載 http://xiazai.jb51.net/jbtools/vb6controls.rar
相關(guān)文章
用vbscript實(shí)現(xiàn)從文本文件中刪除所有重復(fù)行的代碼
這篇文章主要為大家介紹了關(guān)于從文本文件中刪除重復(fù)名字的類似問題,需要的朋友可以參考一下2007-04-04
msxml3.dll 錯(cuò)誤 80070005 拒絕訪問
msxml3.dll 錯(cuò)誤 80070005拒絕訪問。 解決辦法: 賦予程序所在文件夾 internet 來賓帳號(IUSR_WEB)可寫。2011-01-01
用vbs實(shí)現(xiàn)配置無人登錄計(jì)算機(jī)時(shí)使用的屏幕保護(hù)程序
用vbs實(shí)現(xiàn)配置無人登錄計(jì)算機(jī)時(shí)使用的屏幕保護(hù)程序...2007-03-03
用VBScript批量安裝網(wǎng)絡(luò)打印機(jī)和設(shè)置默認(rèn)打印機(jī)
假如你有幾十臺(tái)機(jī)器,幾臺(tái)打印機(jī),共享網(wǎng)絡(luò)上有網(wǎng)絡(luò)打印機(jī)的安裝驅(qū)動(dòng),可是每臺(tái)電腦都點(diǎn)擊幾次驅(qū)動(dòng)十分麻煩,本人做了個(gè)VBS,這樣就方便多了,拿來和大家分享,不足之處請見諒!2009-03-03
用VBS實(shí)現(xiàn)的批量gb2312轉(zhuǎn)utf-8,支持拖動(dòng)
用VBS實(shí)現(xiàn)的批量gb2312轉(zhuǎn)utf-8,支持拖動(dòng)...2007-10-10
用vbscript實(shí)現(xiàn)啟用 Caps Lock (大寫)鍵
用vbscript實(shí)現(xiàn)啟用 Caps Lock (大寫)鍵...2007-04-04

