您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“如何用vbs刪除某些類型文件和磁盤空間報(bào)告”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“如何用vbs刪除某些類型文件和磁盤空間報(bào)告”吧!
Option Explicit
dim ServerPath,onlyone,notfinddel,WorkPath,arrWorwpath,strWorkPath,fso,wsh,WshNetwork,cName,exectime,fnum,donum,totalsize,t1,t2,tm
fnum=0
donum=0
totalsize=0
WorkPath = "F:\|D:\|C:\Download\" '這里設(shè)置需要掃描的路徑(絕對(duì)路徑),使用“|”來(lái)分隔多個(gè)路徑
serverpath = "\\server\log$\" '在這里設(shè)置服務(wù)器上的共享文件夾(可寫共享),用來(lái)存放刪除日志
onlyone = "是" '設(shè)置是否只掃描一次,如果想每次運(yùn)行都掃描,請(qǐng)改為“否”。
notfinddel = "是" '如果本次運(yùn)行沒(méi)有找到任何要?jiǎng)h除的內(nèi)容,就刪除日志文件,(你想每次都保留日志的話,請(qǐng)改為“否”)
If Right(serverpath,1) <> "\" Then serverpath = serverpath&"\"
arrWorwpath = Split(WorkPath,"|")
t1 = timer()
Set WSH = WScript.CreateObject("WScript.Shell")
wsh.run "regsvr32 /s scrrun.dll",0,true
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")
cName = WshNetwork.ComputerName
exectime = Now()
Dim dicdrv,logfile,logfilepath,Objdrv,drvTotalSize,drvFreeSpace
logfilepath = Replace(ServerPath&cName&".txt",":","-")
If Not fso.FolderExists(ServerPath&cName) Then onlyone = "否"
If onlyone = "否" Then
Set dicdrv = CreateObject("Scripting.Dictionary")
Set logfile = fso.OpenTextFile(logfilepath,8,True)
logfile.WriteBlankLines(1)
logfile.WriteLine "#####################################################"
logfile.WriteLine "開始掃描--"&Now()
logfile.WriteBlankLines(1)
For Each strWorkPath In arrWorwpath
If Right(strWorkPath,1) <> "\" Then strWorkPath = strWorkPath&"\"
scan(strWorkPath)
If Not dicdrv.Exists(UCase(Left(strWorkPath,1))&"t") Then
Set Objdrv = fso.GetDrive(fso.GetDriveName(Left(strWorkPath,2)))
dicdrv.add UCase(Left(strWorkPath,1))&"t",FormatNumber(Objdrv.TotalSize/1048576, 0)
dicdrv.add UCase(Left(strWorkPath,1))&"f",FormatNumber(Objdrv.FreeSpace/1048576, 0)
End If
Next
t2 = timer()
tm=cstr(int(( (t2-t1)*10000 )+0.5)/10)
logfile.WriteBlankLines(1)
logfile.WriteLine "完成掃描,檢查 "&fnum&" 個(gè)文件,共刪除 "&donum&" 個(gè)文件,計(jì) "&FormatNumber(totalsize,0)&" Kb"
Dim drvkey,i
drvkey = dicdrv.Keys
For i = 0 To dicdrv.Count-1 Step 2
logfile.WriteLine Left(drvkey(i),1)&"盤:總計(jì)磁盤空間 "&dicdrv.Item(drvkey(i))&" M ,剩余磁盤空間 "&dicdrv.Item(drvkey(i+1))&" M"
Next
logfile.WriteLine "耗時(shí) " & tm & " 毫秒, "&Now()
logfile.WriteLine "#####################################################"
logfile.WriteBlankLines(1)
logfile.close
If notfinddel = "是" Then
If donum = 0 Then fso.DeleteFile logfilepath,True
End If
If Not fso.FolderExists(ServerPath&cName) Then fso.CreateFolder(serverpath&cName)
msgbox "找到 "&fnum&" 個(gè)文件"&chr(10)&"已刪除 "&donum&" 個(gè)"&chr(10)&"耗時(shí) " & tm & " 毫秒"
'不需要在客戶機(jī)上顯示執(zhí)行結(jié)果的話,注釋掉上面這一行
end if
wsh.run "regsvr32 /u /s scrrun.dll",0,true
Set WshNetwork = Nothing
Set wsh=NoThing
Set FSO=NoThing
WScript.quit
Sub scan(strfolder_)
Dim folder_,files,file,ext,subfolders,subfolder
'on error resume next
Set folder_=fso.getfolder(strfolder_)
Set files=folder_.files
For Each file In files
fnum = fnum+1
ext=fso.GetExtensionName(file)
ext=lcase(ext)
Select Case ext
Case "rm","rmvb","mpg","wmv","mpeg","3gp","mp4" '這里是你要?jiǎng)h除的文件類型,當(dāng)然也可以是如"td","pdown"等^^文件
doit(file)
End Select
Next
set subfolders=folder_.subfolders
For Each subfolder In subfolders
If subfolder.name <> "System Volume Information" And subfolder.name <> "RECYCLER" Then
scan(subfolder)
End If
Next
End Sub
Sub doit(file)
Dim strtemp,lngsize,strsizeV
strtemp = file.path
lngsize = clng(file.size/1024)
donum=donum+1
totalsize = totalsize + lngsize
'fso.DeleteFile file,True '如果你只是想看看顧客都下了些什么,就把此行注釋掉(呵呵,是不是你也想看啊)
logfile.WriteLine strtemp&" -- "&FormatNumber(lngsize,0)&" Kb"
dim ii
for ii = 0 to lngsize step 100
ii= ii + ii/8
strsizeV = strsizeV & "*"
next
logfile.WriteLine "---"&strsizeV
end Sub
到此,相信大家對(duì)“如何用vbs刪除某些類型文件和磁盤空間報(bào)告”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。