com open boxes
cd = new ActiveXObject("MSComDlg.CommonDialog")
cd.Filter = "All Files(*.*)|*.*|JScript Files(*.js)|*.js"
cd.FilterIndex = 2
// Must set MaxFileSize. Otherwise you will get an error
cd.MaxFileSize = 128
cd.ShowOpen()
file = cd.FileName
if(!file) {
WScript.Echo("You must enter a file name")
WScript.Quit(0)
}
else {
WScript.Echo("The user selected:\n" + file )
}
--------------------------------------------------------------------------------
function lib_comdlg(path,filter) {
path = (path) ? path : '.'
filter = (filter) ? filter : 'All Files (*.*)|*.*|Text Files (*.txt)|*.txt'
try {
// check for commondialog (xp only)
var cdlg = new ActiveXObject('useraccounts.commondialog')
cdlg.filter = filter
cdlg.filterindex = 1
cdlg.initialdir = path
var bool = cdlg.showopen()
if(!bool)
return(0)
var file = cdlg.filename
delete(cdlg)
} catch(e) {
// else use form.input.file workaround
if(!document.comdlgx)
document.body.insertAdjacentHTML('beforeEnd','')
document.comdlgx.comdlg.click()
var file = document.comdlgx.comdlg.value
document.comdlgx.reset()
}
return(file)
}
function init() {
var file = lib_comdlg('c:\\')
if(file)
alert(file)
self.close()
return(0)
}
lib_comdlg()