编程技术、软件应用与系统模拟

(Programming, Applicaiton and Simulation)



本站目录

 

首页
ASP/Access/IIS
DELPHI/PASCAL
PASCAL高级编程
C语言编程实例
WORD
Excel
MATLAB
MINITAB讲座
Windows
DOS
SAS
生物系统模拟
土壤水分剖析器
其他



镜像站点

 

主站
北美镜象站
欧洲镜象站(1)
欧洲镜象站(2)

本站 Google

[搜索]  [站内导航]
座右铭:
只做有益人类的事
不做有害人类的事


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

© 1998-, 董占山, 版权所有。
转载文章请注明出处(www.sunfinedata.com/articles)。