读取客户端文件:
<script language="vbscript">
Sub OpenScript
Set objFSO = CreateObject("Scripting.FileSystemObject")
strOpenFileName = InputBox("Please enter the complete path name for your script (for example, C:\Scripts\MyScript.txt).")
If strOpenFileName = "" Then
Exit Sub
End If
Set objFile = objFSO.OpenTextFile(strOpenFileName)
strHTML = "<textarea cols=100 rows=30>"
strHTML = strHTML & objFile.ReadAll()
strHTML = strHTML & "</textarea>"
document.write(strHTML)
objFile.Close
End Sub
</script>
<input type="button" value="打开" onclick="vbscript:OpenScript">
保存页面上内容到客户端指定位置:
<script language="vbscript">
sub save_as()
Set objFSO = CreateObject("Scripting.FileSystemObject")
strSaveFileName = InputBox("Please enter the complete path where you want to save your script (for example, C:\Scripts\MyScript.vbs).")
If strSaveFileName = "" Then
Exit Sub
End If
Set objFile = objFSO.CreateTextFile(strSaveFileName)
objFile.WriteLine code.InnerText
objFile.Close
end sub
</script>
<div id="code">Hello,I am possible !</div>
<br><input type="button" onclick="vbscript:save_as()">
文件的遍历:
<script language=vbs>
Set fso=CreateObject("Scripting.FileSystemObject")
set getfso=fso.GetFolder("c:\").files
document.write "以下是c:所有文件"
for each i in getfso
document.write i & "<br>"
next
document.write "<p>以下是d:所有文件子文件夹包含的文件夹和文件<p>"
set getfso=fso.GetFolder("d:\").SubFolders
for each r in getfso
document.write r & " 文件夹包含<p>"
set getfso1=fso.GetFolder(r).files
for each n in getfso1
document.write n & "<br>"
next
next
</script>
删除客户端文件:
<script language="vbscript">
Sub OpenScript
Set objFSO = CreateObject("Scripting.FileSystemObject")
strOpenFileName = InputBox("Please enter the complete path name for your script (for example, C:\Scripts\MyScript.txt).")
If strOpenFileName = "" Then
document.all("code").InnerHTML = "请输入路径!"
Exit Sub
End If
if objFSO.FileExists(strOpenFileName) then
objFSO.DeleteFile strOpenFileName
document.all("code").InnerHTML = "删除"&strOpenFileName&"!"
f1.Close
else
document.all("code").InnerHTML = "找不到"&strOpenFileName
End If
Set objFSO = Nothing
End Sub
</script>
<input type="button" value="选择删除" onclick="vbscript:OpenScript()"><br><br>
<div id="code"></div>
获取客户端某个文件的名字,文件大小:
<script language="vbscript">
function myfile()
url=f1.my.value
Set fso=CreateObject("Scripting.FileSystemObject")
Set fl=fso.getfile(url)
flsize=fl.size
flName=fl.name
Set fl=Nothing
Set fso=Nothing
msgbox("文件:"&flName&" 大小:"&flsize&"字节")
End function
</script>
<form name="f1">
<input type="file" name="my" onblur="vbscript:myfile()">
</form>