VBS之根据磁盘空间的大小来删除指定文件夹 - 网吧VBS - 无题网-我的网吧网管生活

TOP

VBS之根据磁盘空间的大小来删除指定文件夹
[ 录入者:868com | 时间:2008-05-31 19:48:29 | 作者: | 来源: | 浏览:10次 ]

Option Explicit
Dim strChkPath,strDelFod,intLessthan,objFso

strDelFod = "c:\netgame\文件夹1|e:\netgame\文件夹1|f:\文件夹1|d:\文件夹2"   '可以删除的文件夹组,用“|”分隔
intLessthan = 20000     '少于多少MB

Set objFso = CreateObject("Scripting.FileSystemObject")
Dim arrDelFod,dicDrvState
Set dicDrvState = CreateObject("Scripting.Dictionary")
arrDelFod = Split(strDelFod,"|",-1)
Dim DelFod,drvPath
For Each DelFod In arrDelFod
   drvPath = UCase(objFso.GetDriveName(DelFod))
   dicDrvState.Item(drvPath) = GetFreeSpace(drvPath)
   If dicDrvState.Item(drvPath) < FormatNumber(intLessthan,0) Then
      If Ask(drvPath&" 盘小于 "&FormatNumber(intLessthan,0)&" MB,是否要删除 “"&DelFod&"”") Then
         On Error Resume Next
         objFso.DeleteFolder DelFod,True
         If Err Then
            err.Clear
            Msgbox "不能删除文件夹,请检查 “"&DelFod&"”"&vbCrLf&"按确定继续",16,"错误"
         End If
         On Error GoTo 0
      End If
   End If
Next   

Dim strMmg,keyDrv,i
strMmg = "完成报告:"&vbCrLf&vbCrLf
keyDrv = dicDrvState.Keys
For i = 0 To dicDrvState.Count -1
strMmg = strMmg & keyDrv(i)&" 盘剩余空间        "&dicDrvState(keyDrv(i))&"        "
If dicDrvState(keyDrv(i)) < FormatNumber(intLessthan) Then strMmg = strMmg & "注意!"
strMmg = strMmg & vbCrLf
Next
MsgBox strMmg,64,"完成报告"
Set dicDrvState = NoThing
Set objFso = NoThing
WScript.quit
      
Function GetFreeSpace(drvPath)
   Dim fso, d
   Set fso = CreateObject("Scripting.FileSystemObject")
   On Error Resume Next
   Set d = fso.GetDrive(fso.GetDriveName(drvPath))
   If Err Then
      err.Clear
      Msgbox "不能找到驱动器 “"&drvPath&"” 按确定继续",16,"错误"
      GetFreeSpace = "Error"
      Exit Function
   End If
   On Error GoTo 0
   GetFreeSpace = FormatNumber(d.FreeSpace/1048576, 0)
   Set fso = Nothing 
End Function

Function Ask(strAction)
    Dim intButton
    intButton = MsgBox(strAction,vbQuestion + vbYesNo,"询问")
    Ask = intButton = vbYes
End Function

将以上内容保存为VBS即可.如果你的VBS无法运行,请看这篇文章:http://868com.com/20611.html

2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】 【关闭】 【返回顶部
[上一篇]VBS删除指定类型文件 [下一篇]VBS显示计算机名和IP地址

评论

称  呼:
内  容:

相关栏目

最新文章

热门文章

推荐文章

相关文章

广告位