vbs选择文件夹效果代码
程序员文章站
2022-07-04 17:20:23
不用组件的话有两种办法: set objfile = createobject("safrcfiledlg.fileopen")&...
不用组件的话有两种办法:
set objfile = createobject("safrcfiledlg.fileopen")
set objshell = createobject("shell.application")
本blog里都有示例。
如果调用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
组件相关文件下载
set objfile = createobject("safrcfiledlg.fileopen")
set objshell = createobject("shell.application")
本blog里都有示例。
如果调用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
组件相关文件下载
上一篇: 查看物理内存的批处理