Programming and Application(编程与应用)


Content(目录)




Linux


MySQL
Office















 
PCNow 30-Day Free Trial, Remote PC Access
 
Logo_234x60

Cleaning up your hard disk automatically

Cleaning up your hard disk automatically
Zhanshan Dong

There are a bunch of garbage files in your hard drive. It is hard to clean them up at one
time. You have to use Windows Explorer to find and delete them manually. Windows Script
Host provides us a potential to write a short script to execute repetitive jobs.

After I read an article in PC Magazine, I wrote the Windows script file to clean my hard
disk. The following VBScript file can clean Windows temporary folder, recycle bin, and
three specific temporary files with the extensions of .~, .BAK, and .$$$. It runs in the
background. You can put it on your desktop. If you need to clean your hard disk, just doule
click it. The source code is listed below.

Option Explicit
Dim FSO, WshShell, WSHShellENV, TempFolder, Recycled
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
set WshShell = WScript.CreateObject("WScript.Shell")
Set WSHShellENV = WshShell.Environment("PROCESS")
set TempFolder = FSO.GetFolder(WSHShellENV("TEMP"))
ClearFolder TempFolder
Set Recycled = FSO.GetFolder("C:\recycled")
ClearFolder Recycled
DoDir FSO.GetFolder("c:\")
WScript.Echo "Cleaning job finished"

Sub DoDir(Folder)
   Dim i, File, SubFolder, fstr, pos
   Dim Findstr(2)
   Findstr(0) = ".$$$"
   Findstr(1) = ".BAK"
   Findstr(2) = ".~??"
   For Each File In Folder.Files
      FStr = UCase(File.Path)
      Pos = 0
      for i = 0 to 2
      	if instr(FStr, FindStr(i)) > 0 then
      	   File.delete
      	   Exit For
      	End if
      Next
   Next
   For Each SubFolder in Folder.SubFolders
      DoDir SubFolder
   Next
End Sub

Sub ClearFolder(Folder)
   Dim File, SubFolder
   For each file in Folder.Files
   	File.delete(True)
   next
   For Each SubFolder in Folder.SubFolders
      SubFolder.Delete(True)
   Next
End Sub
     Download source code ©董占山Zhanshan Dong

Post comments(留言)

Name(名字):

Comment(内容):


由Google提供

SunfineData Products|U's Bargain Network|Contact Me(与我联系)
© 1998-, 董占山, 版权所有, 欢迎转载文章链接。
转载文章和软件请注明出处(http://articles.sunfinedata.com/)。