WSH刪除一個檔案的範例


Tek 發表



輸入一個檔案的位置,會先檢查檔案是否存在後,再詢問是否要刪除的簡單WSH!

Windows Script Host,一個簡單的範例...輸入一個檔案的位置,就幫您刪除該檔案的範例•
檔案名:delete.vbs

'///////////////////////////////////////////////////////////////////////
'coded by tek
'cx@ms74.url.com.tw
'purpose:刪除檔案用
'caution:
'在使用此程式時,請確定防毒程式的script blocking功能已經關閉•
'如果您的wscript.exe未設定過,請到『開始』->『執行』中輸入
'"wscript.exe",調整持續執行wsh程式的秒數(建議調整至60)•
'///////////////////////////////////////////////////////////////////////
'declare all the variables
Dim fso, requestfile, fn, drivefilter, gfile, askin
set fso = wscript.createobject("scripting.filesystemobject")
requestfile = inputbox("請輸入一個檔案位置(包括副檔名)...","請選擇位置")
driverfilter = mid(requestfile,1,instr(requestfile,"\"))
fname = instrrev(requestfile,"\")+1
If requestfile = empty then
wscript.quit
else
If instr(requestfile,"/") >= 1 Then
Wscript.echo "資料中禁止使用 / 符號"
else
If fso.driveexists(driverfilter) = TRUE Then
If fso.fileexists(requestfile) = TRUE then
wscript.echo mid(requestfile,fname,len(requestfile)) & " 檔案存在"
set gfile = fso.getfile(requestfile)
askin = msgbox("當刪除此檔案後,該檔將不會出現在資源回收筒(完全刪除),您要刪除此檔嗎?",4,"要求確認") 'the final check
if askin = 6 then
gfile.delete 'delete the file
wscript.echo mid(requestfile,fname,len(requestfile)) & "檔案已經刪除"
end if
else
wscript.echo mid(requestfile,fname,len(requestfile)) & " 檔案不存在"
end if
else
wscript.echo driverfilter & " 不存在!"
end if
end if
end if

最後更新日期: 9/5/2002 9:54:42 AM