|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[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! |
||
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: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: |
'First, you will need to setup a scheduled task and run it
'daily. Just change the number to the amount of days you
'want to keep file in that directory. Any files in the
'directory will be deleted.
' specify the directory you wish to clean as the first and only parameter to this script!
' MODIFIED AND ENHANCED BY RUSSELL JUNGWIRTH
' FROM AN ORIGINAL SCRIPT Courtesty of monsterjta @ tek-tips.com
Option Explicit
on error resume next
Dim iDaysOld
Dim WshShell
Dim sDirectoryPath
Dim DesktopFolder
Dim LogFilePath
Dim fso
Dim LogFile
Dim oArgs
Dim bWriteLog
Dim bDoDeletes
'Definitions
' change this value to specify the number days old the file must be to qualify for deletion
iDaysOld = 90
' set this to 1 to log activity, set to 0 to prevent logging
' THE LOG FILE LIVES IN THE SAME DIRECTORY AS THE SCRIPT
bWriteLog = 1
' set to 1 to do the deletions, set to 0 to simply report intended deletions instead of doing them
' note that setting this to 1 will automatically write a log
bDoDeletes = 1
if bDoDeletes = 0 and bWriteLog = 0 then bWriteLog = 1
Set WshShell = CreateObject("WScript.Shell")
OpenLog()
WriteLog("run " & fso.GetBaseName(Wscript.ScriptName))
' GET EXECUTION ARGUMENTS TO DETERMINE WHAT DIR TREE TO SCAN
Set oArgs = WScript.Arguments
sDirectoryPath = oArgs(0)
if sDirectoryPath = "" then
'wscript.stderr.writeline("no directory specified")
'wscript.quit(1)
sDirectoryPath = WshShell.CurrentDirectory
end if
' CALL THE RECURSIVE SUB TO DO THE WORK
call DeleteTree(sDirectoryPath)
If Err.Number <> 0 Then
writelog("subfolder err " & Err.Number & " - " & Err.Description)
on error goto 0
Err.Clear
end if
CloseLog()
'Clean up
set fso = Nothing
set WshShell = Nothing
set LogFile = Nothing
set oArgs = Nothing
'End
Sub DeleteTree (ByVal sPath)
on error resume next
Dim l_oFile, l_oFolder, l_oFileCollection
Dim l_oFSO, l_oFolderCollection
' WriteLog("called DelTree with " & sPath)
if mid(len(sPath),1) <> "\" then sPath = sPath & "\"
Set l_oFSO = CreateObject("Scripting.FileSystemObject")
set l_oFolder = l_oFSO.GetFolder(sPath)
set l_oFileCollection = l_oFolder.Files
For each l_oFile in l_oFileCollection
If l_oFile.DateLastModified < (Date() - iDaysOld) Then
WriteLog("delete " & l_oFile.Name)
if bDoDeletes = 1 then l_oFile.Delete(True)
else
WriteLog("preserve " & l_oFile.Name)
End If
Next
set l_oFolderCollection = l_oFolder.SubFolders
If Err.Number <> 0 Then
writelog("subfolder err " & Err.Number & " - " & Err.Description)
on error goto 0
Err.Clear
exit sub
else
For each l_oFolder in l_oFolderCollection
' PERFORM RECURSIVE CALL TO DELETE OLD FILES IN LOWER DIRECTORIES
' WriteLog("recurse " & l_oFolder.Path)
DeleteTree(l_oFolder.Path)
on error resume next
' WriteLog("return recurse " & l_oFolder.Path)
' if l_oFolder.Files.Count = 0 and l_oFolder.SubFolders.Count = 0 and l_oFolder.DateLastModified < (Date() - iDaysOld) then
' WriteLog("delete empty folder " & l_oFolder.Path)
' if bDoDeletes = 1 then l_oFolder.Delete(True)
' else
' WriteLog("preserve non-empty folder " & l_oFolder.Path)
' end if
' On Error Goto 0
Next
end if ' error trap
Set l_oFile = Nothing
Set l_oFolder = Nothing
Set l_oFileCollection = Nothing
Set l_oFSO = Nothing
Set l_oFolderCollection = Nothing
End Sub
Sub OpenLog()
on error resume next
if bWriteLog = 1 then
' GET LOCATION FOR LOG FILE ON THE DESKTOP
' DesktopFolder = WshShell.RegRead("HKEY_CURRENT_USER\Software\" & _
' "Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop")
Set fso = CreateObject("Scripting.FileSystemObject")
' LogFilePath = DesktopFolder & "\" & fso.GetBaseName(Wscript.ScriptName) & ".log"
LogFilePath = fso.GetParentFolderName(WScript.ScriptFullName) & "\" & fso.GetBaseName( Wscript.ScriptName) & ".log"
'wscript.stderr.writeline(logfilepath)
if not fso.FileExists(LogFilePath) then
Set LogFile = fso.CreateTextFile(LogFilePath)
else
Set LogFile = fso.OpenTextFile(LogFilePath, 8) ' open for appending = 8
'Set LogFile = fso.OpenTextFile(LogFilePath, 2) ' open for writing = 2
end if
end if
End Sub
Sub WriteLog(sLogEntry)
on error resume next
if bWriteLog = 1 then LogFile.WriteLine(Now & " " & sLogEntry)
end Sub
Sub CloseLog()
on error resume next
if bWriteLog = 1 then LogFile.Close()
End Sub
|
Advertisement
| Hall of Fame |