vbs选择文件夹效果代码
vbs选择文件夹效果代码
发布时间:2016-12-28 来源:查字典编辑
摘要:不用组件的话有两种办法:setobjFile=CreateObject("SAFRCFileDlg.FileOpen")SetobjShel...

不用组件的话有两种办法:

setobjFile=CreateObject("SAFRCFileDlg.FileOpen")

SetobjShell=CreateObject("Shell.Application")

本blog里都有示例。

如果调用vb组件,可以是:

flag=&h200

whichone=OpenFile("ChooseaFile!","C:","Everything|*.*|TextFiles|*.TXT|Word-Documents|*.DOC",2,flag)

MsgBox"Rawdatareturned:"&whichone

'Splitupmultiselectionresult:

'spaceisusedasseparator:

whichone=Split(whichone,"")

'fieldindex0containspathinformation:

path=whichone(0)

'listallthefiles:

'howmanyfileswereselected?

filecount=UBound(whichone)

iffilecount=0then

'justonefileselected!

MsgBox"Youselectedonefile:"&whichone(0)

'checkstatusofReadOnlycheckbox

'isbit1setorcleared?

'worksonlyifjustonefilewasselected!

MsgBox"Returnedflag:"&flag

if(flagand1)then

'(flagand1)<>0,transformstotrue

'bitisset!

MsgBox"ReadOnlyselected!"

else

MsgBox"ReadOnlynotselected!"

endIf

'checkwhetherselectedfileisofdefaulttype(txt)

if(flagand1024)then

MsgBox"selectedfileisnotxtfile!"

else

MsgBox"selectedfileisofdefaulttype!"

endif

else

'morethanonefileselected!

MsgBox"Youselected"&filecount&"files!"

forx=1toUBound(whichone)

list=list&path&whichone(x)&vbCr

next

MsgBoxlist

endIf

functionOpenFile(title,dir,filter,index,flags)

setcomdlg=CreateObject("MSComDlg.CommonDialog")

comdlg.filter=filter

comdlg.FilterIndex=index

comdlg.Flags=flags

comdlg.MaxFileSize=260

comdlg.CancelError=false

comdlg.DialogTitle=title

comdlg.InitDir=dir

'settxtasdefault

comdlg.DefaultExt="txt"

comdlg.ShowOpen

OpenFile=comdlg.filename

'important:returnflagstatussoyourmainscriptcan

'checkit:

flags=comdlg.Flags

endfunction

组件相关文件下载http://xiazai.jb51.net/jbtools/vb6controls.rar

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新vbs学习
热门vbs学习
脚本专栏子分类