目的:
扫描当前目录及子目录下文件,并显示在HTA的SPAN区域,如果文件后缀是bak则删除这个文件,并显示在删除区域,因为要实时显示,所以要用暂停保证SPAN区域显示了,才进行下步代码.但HTA里没有wscript.sleep 1000 这样的代码,所以使用setInterval
但却不成功
PS:不想使用借用VBS或者CMD实现暂停,因为占内存,并且鼠标一直显示忙碌状态,个人觉得不专业.
以下是代码:
<html><title>HTA template</title><head>
<HTA:APPLICATION
APPLICATIONNAME="HTA Template"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
</head>
<style>
BODY
{
background-color: buttonface;
Font: arial,sans-serif
margin-top: 0px;`
margin-left: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.button
{
width: 91px;
height: 25px;
font-family: arial,sans-serif;
font-size: 8pt;
}
td
{
font-family: arial,sans-serif;
font-size: 10pt;
}
#scroll
{
height:100%;
overflow:auto;
}
SELECT.FixedWidth
{
width: 17em; /* maybe use px for pixels or pt for points here */
}
</style>
<script language="VBScript">
Public fso
Dim iTimerID
Set fso=CreateObject("Scripting.FileSystemObject")
Sub ButtonClick
curPath=Mid(fso.GetParentFolderName(window.location),9)
seek curpath
End Sub
Sub seek(Path)
'Set fso=CreateObject("Scripting.FileSystemObject")
Set curF=fso.GetFolder(path)
If curF.SubFolders.count>0 Then
For Each subf In curF.SubFolders
seek subf
Next
End If
If curF.Files.count>0 Then
For Each file In curF.Files
scaning.innertext=file
iTimerID = window.setInterval("DF(file)",1000)
Next
End If
End Sub
Sub DF(files)
window.clearInterval(iTimerID)
If lcase(fso.GetExtensionName(files))="bak" Then
MsgBox files
done.innertext=done.innertext&vbCr&files
fso.DeleteFile files
End If
End Sub
Sub window_onload
window.resizeTo 700,400
End Sub
</script>
<body >
<p> 点击"查杀"按钮进行查杀:
<input class="button" type=BUTTON value="查杀" name="btnTestButton" onClick="ButtonClick">
</p>
<p> 当前正在查杀:<br>
<font color="#00FF00"><span id="scaning" class="FixedWidth" >请点击“查杀”按钮 </span>
</p>
</font></p>
<p> 被删除的文件:<br> </p> <font color="#00FF00"> <span id="done" class="FixedWidth" > </span></font>
</p>
<p> </p>
<P align="right">
</body></html>