Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Tuesday, November 16, 2004

VBscript that clear temporary files of generated by VC

'*************clear temporary files of generated by VC++, will delete readonly files
'*************usage: clear.vbs C:\temp
'*************usage: clear.vbs "C:\old source\7-23-04"
'*************Author: Onega(www.fruitfruit.com http://fruitfruit.blogspot.com)
'*************Warning: Use it at your own risk!


Dim ArgObj
Set ArgObj = WScript.Arguments

'***************create array containing postfix of file names. Those files are to be deleted
Dim dict
Set dict = CreateObject("Scripting.Dictionary")
dict.Add dict.count , ".obj" 'Object File
dict.Add dict.count , ".ncb" 'Visual C++ Intellisence Database
dict.Add dict.count , ".plg"
dict.Add dict.count , ".aps"
dict.Add dict.count , ".ilk"
dict.Add dict.count , ".pch"
dict.Add dict.count , ".pdb"
dict.Add dict.count , ".idb"
dict.Add dict.count , "BuildLog.htm"
dict.Add dict.count , ".tli"
dict.Add dict.count , ".tlh" '
dict.Add dict.count , ".suo" 'Visual Studio Solution User Options
dict.Add dict.count , ".opt"
dict.Add dict.count , ".sbr" 'Source Browser Intermediate File
dict.Add dict.count , ".bsc" 'Source Browser Database
'dict.Add dict.count , ".res" '

On Error Resume Next


If ArgObj.Count>0 Then
object_folder = ArgObj(0)
Set IFileSystem3 = CreateObject("Scripting.FileSystemObject")
set IFolder = IFileSystem3.GetFolder(object_folder)
clear_folder IFolder
MsgBox "finished"
Else
MsgBox "Usage: clear.vbs C:source"
End If


Function clear_folder( folder )
set IFileCollection = folder.Files
For each file in IFileCollection
If is_temp_file( file.Path ) Then
file.Delete true
If Err <> 0 Then
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description & " file:" & file.Path
Err.Clear ' Clear the error.
End If

End If
Next

For each sub_folder in folder.SubFolders
clear_folder sub_folder
Next
End Function



Function end_with( src_string, key)
end_with = false
If Len(key) <1 Then
end_with = false
Exit Function
End if
If Len(src_string) < Len(key) Then
end_with = false
Else
Dim temp_str
temp_str = right(src_string, Len(key) )
'vbTextCompare = 1
If StrComp( temp_str,key,vbTextCompare) = 0 Then
end_with = true
Else
end_with = false
End if
End if

End function

Function is_temp_file(path)
is_temp_file = false
For each postfix in dict.items
If end_with(path, postfix) Then
is_temp_file = true
Exit for
End if
next
End function

0 Comments:

Post a Comment

<< Home