vbs实用代码 vbs代码,纯自己采集,绝对良心!( 三 )



logfile = "C:\EmptyDelete.log"

set logbook = objfso.OpenTextFile(logfile, 8, true)

Call CheckDiskFile(getdrv,ext)

logbook.Close

WshShell.Popup "检查完毕!" & vbCrLf & "(c) Zero 2014",5, "谢谢使用",vbInformation+vbokOnly

Case 2: '搜索空文件夹

getdrv = InputBox("请输入需要处理的盘符"& "格式如下:E","盘符","E")
getdrv = getdrv & ":\"
logfile = "C:\EmptyDelete.log"
set logbook = objfso.OpenTextFile(logfile, 8, true)

set drive = objfso.GetDrive(getdrv)

CheckFolder drive.RootFolder

logbook.Close

WshShell.Popup "检查完毕!" & vbCrLf & "(c) Zero 2014",5, "谢谢使用",vbInformation+vbokOnly



select




Else If confirm= vbno Then
MsgBox "你会回来的!" & vbCrLf & "(c) Zero 2014" , vbOKOnly+ vbError,"提示"

WScript.Quit

If

If


'/// 主程序部分结束

'/// /////////////////////////////////////////////检查空文件部分开始////////////////////////

Function CheckDiskFile(drv,ext)
extTemp = ext

On Error Resume Next
Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")

Set drvRootFiles = fso.GetFolder(drv)

Set files = drvRootFiles.Files

For Each file In files

IsEmptyFile file,extTemp

Next

Set subfoldertemp = fso.GetFolder(drv)

Set subfolders = subfoldertemp.SubFolders

For Each subfolder In subfolders

CheckDiskFile subfolder,extTemp '递归

Next


Function

'/// 测试是否为空文件
Sub IsEmptyFile(file,ext)

OnError Resume Next

Set fso = CreateObject("Scripting.FileSystemObject")

extFile = fso.GetExtensionName(file)

If file.Size = 0 And extFile = extThen

ReportEmpty file

If


Sub

'/// 写入日志文件
FunctionReportEmpty(file)
On Error Resume Next

response = MsgBox("我们在" & vbCr & file.Path & "发现了空文件," &_
"你想删除吗?", vbYesNo + vbDefaultButton1,"提示")

If vbyes = response Then

logbook.WriteLine vbCrLf
logbook.WriteLine "[文件:]"

logbook.WriteLinefile.Path & vbCrlf & " 在 " & Now & " 被删除"
objfso.DeleteFile file, True


end If

Function

'/// /////////////////////////////////////////////检查空文件部分结束////////////////////////


'/// /////////////////////////////////////////////检查空文件夹部分开始//////////////////////

sub CheckFolder(folderobj)

on error resume Next

isEmptyFolder folderobj

for each subfolder in folderobj.subfolders

CheckFolder subfolder

Next

end Sub

sub isEmptyFolder(folderobj)

on error resume Next

if folderobj.Size=0 and err.Number=0 then

if folderobj.subfolders.Count=0 Then

ReportEmptyFolder folderobj

end If

end If

end Sub



sub ReportEmptyFolder(folderobj)

on error resume next

lastaccessed = folderobj.DateLastAccessed

on error goto 0

response = MsgBox("我们在:" & vbCr _
& folderobj.path & vbCr & "发现了空文件夹 " & "文件夹最后访问时间:" _
& vbCr & lastaccessed & vbCr _
& "你想删除这个文件夹么?", _
vbYesNoCancel + vbDefaultButton2)

if response = vbYes Then


logbook.WriteLine "[文件夹:]"


以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: