手机
当前位置:查字典教程网 >脚本专栏 >vbs >vbs选择文件夹效果代码
vbs选择文件夹效果代码
摘要:不用组件的话有两种办法: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读取文本文件的最后一行

vbs正则表达式代码

用vbs实现取消隐藏文件夹中的所有文件

黑客必须要知道的几个vbs文件代码

用vbs分割与合并文本文件的代码

vbs获取当前路径的代码

vbs 调用中文语音让你电脑听你的命令的实现代码

vbs 搜索代理地址实现代码[小偷程序]

用vbs实现判断计算机是笔记本还是台式机的代码

vbs实现压缩文件夹的脚本

精品推荐
分类导航