Advertisement
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
|
Loading Advertisement... |
| Open Discussion |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: |
'====================================
' VBScript Source File
' NAME: DeleteEmptySubdirs.vbs
' AUTHOR: Chay Harley
' DATE : v1.0: 28/10/2005 ; v1.1: 30/10/2005 ; v1.2 31/10/2005
' Usage:
' cscript scriptname.vbs /d:C:\SomePath
' cscript scriptname.vbs /d:"C:\SomePath To Clean"
'====================================
Option Explicit
Dim WSHShell, RightMargin, LastParentFolder
Set WSHShell = CreateObject("Wscript.Shell")
If WScript.Arguments.Named.Count = 0 Then Usage()
Dim ExceptionList
'To exclude some folders, add to this list
ExceptionList = Array("Audio_TS", "My Documents", "My Pictures", "My Received Files")
Dim Path
Path = WScript.Arguments.Named.Item("D")
If Right(Path,1) <> "\" Then Path = Path & "\"
WScript.echo "Option [D]: " & UCase(Path)
Dim objFSO, objRootFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRootFolder = objFSO.GetFolder(Path)
ProcessChildFolders objRootFolder
Sub ProcessingDirError(DirToCheck, ErrMsg)
'If we get 'permission denied', there is a read/delete block on the folder. Ignore it...
If ucase(ErrMsg) <> "PERMISSION DENIED" Then
WScript.Echo "Error [" & ErrMsg & "]. Please manually action """ & DirToCheck & """"
End if
Err.Clear
End Sub
Sub CheckAndDeleteEmptyFolder(objFolder)
On Error Resume Next
if objFolder.Size = 0 Then
If Err.Number Then
ProcessingDirError objFolder.Path, Err.Description
else
DeleteEmptyFolder objFolder, objFolder.Size
End If
End If
End Sub
Sub ProcessChildFolders(objRootFolder)
On Error Resume Next
Dim objParentFolder, objChildFolder
Set objParentFolder = objFSO.GetFolder(objRootFolder.Path)
If Err.Number Then
ProcessingDirError objRootFolder.Path, Err.Description
Else
If objParentFolder.SubFolders.Count > 0 Then
'process a folder branch
For Each objChildFolder In objParentFolder.SubFolders
ProcessChildFolders objChildFolder
Next
CheckAndDeleteEmptyFolder objParentFolder
Else
'Process a folder leaf (final folder)
if Left(objParentFolder.Path, InStr(InStr(objParentFolder.Path,"\")+1, objParentFolder.Path,"\")) <> LastParentFolder Then
WScript.Echo "[Progress] " & objParentFolder.Path
End If
CheckAndDeleteEmptyFolder objParentFolder
LastParentFolder = Left(objParentFolder.Path, InStr(InStr(objParentFolder.Path,"\")+1,objParentFolder.Path,"\"))
End If
End if
End Sub
Sub DeleteEmptyFolder(objDeleteFolder, FolderSize)
Dim ExceptionItem
For Each ExceptionItem In ExceptionList 'skip exceptions ;)
If InStr(UCase(objDeleteFolder.Path), Ucase(ExceptionItem)) Then
WScript.Echo "[Skipping] " & objDeleteFolder.Path
Exit Sub
End If
Next
DisplayDirectoryName objDeleteFolder.Path, FolderSize
Err.Clear
objDeleteFolder.Delete()
If Err.Number Then ProcessingDirError objDeleteFolder.Path, Err.Description
End Sub
Sub DisplayDirectoryName(DisplayPath, Size)
Dim TempNumber
TempNumber = Len(DisplayPath)
'set the right margin to make the output look good
If TempNumber > RightMargin Then RightMargin = TempNumber
'yet, let's shift it back to the left if there's a huge difference (say, 30 chars)
If RightMargin - 30 > TempNumber Then RightMargin = TempNumber
WScript.Echo "*Deleting* " & DisplayPath & Space(RightMargin - TempNumber + 4 ) & "Size: " & Size
End Sub
Sub Usage()
WScript.Echo VbCrLf
WScript.Echo "====================================="
WScript.Echo "Empty Folder/Directory Remover Script"
WScript.Echo "====================================="
WScript.Echo VbCrLf & "Usage:"
WScript.Echo VbCrLf & " cscript scriptname.vbs /d:C:\SomePath "
WScript.Echo VbCrLf & " cscript scriptname.vbs /d:""C:\SomePath To Clean"" "
WScript.Quit
End Sub
|