Announcement

Collapse
No announcement yet.

Cleaning up code help..

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cleaning up code help..

    Hey guys.. I'm new to VBScript and I'm just after a bit of help cleaning up a script, I have lots of duplicate code.. Any help or pointers would be much appreciated!

    Code:
    Option Explicit
    
    On Error Resume Next
    
    	Dim oFSO
    	Dim sBaseDirectory
    	Dim sDirectoryPath, sDirectoryPath1, sDirectoryPath2, ArchPath
    	Dim oFolder, oFolder1, oFolder2, objFolder, objFolder1, objFolder2, objFolder3
    	Dim oFileCollection, oFileCollection1, oFileCollection2
    	Dim oFile, oFile1, oFile2
    	Dim fExceptions, fDebug, fInfo, fOrderAudit
    	
    		Set oFSO = CreateObject("Scripting.FileSystemObject")
    		sBaseDirectory = "D:\_awcgateway"
    
    Call CheckArchFolders
    Call DelBuffer
    Call DelArchDebug
    Call DelArchExceptions
    Call MovingLogFiles
    
    Dim iDaysOld
    
    iDaysOld = 14
    
    Sub CheckArchFolders
    
    ArchPath = sBaseDirectory & "\Archive\"
    fExceptions = ArchPath & "\Exceptions\"
    fDebug = ArchPath & "\Debug\"
    fInfo = ArchPath & "\Info\"
    fOrderAudit = ArchPath & "\OrderAudit\"
    
    If oFSO.FolderExists(fExceptions) Then
    	Set objFolder = oFSO.GetFolder(fExceptions)
    		Else
    	Set objFolder = oFSO.CreateFolder(fExceptions)
    End If
    
    If oFSO.FolderExists(fDebug) Then
    	Set objFolder1 = oFSO.GetFolder(fDebug)
    		Else
    	Set objFolder1 = oFSO.CreateFolder(fDebug)
    End If
    
    If oFSO.FolderExists(fInfo) Then
    	Set objFolder2 = oFSO.GetFolder(fInfo)
    		Else
    	Set objFolder2 = oFSO.CreateFolder(fInfo)
    End If
    
    If oFSO.FolderExists(fOrderAudit) Then
    	Set objFolder3 = oFSO.GetFolder(fOrderAudit)
    		Else
    	Set objFolder3 = oFSO.CreateFolder(fOrderAudit)
    End If
    
    End Sub
    
    Sub DelBuffer
    
    	sDirectoryPath = sBaseDirectory & "\buffers\"
    	set oFolder = oFSO.GetFolder(sDirectoryPath)
    	Set oFileCollection = oFolder.Files
    
    	For each oFile in oFileCollection
    		If oFile.DateLastModified < (Date() - iDaysOld) Then
    			oFile.Delete(True)
    		End If
    	Next	
    
    End Sub
    
    Sub DelArchDebug
    
    	sDirectoryPath1 = sBaseDirectory & "\archive\debug\"
    	set oFolder1 = oFSO.GetFolder(sDirectoryPath1)
    	set oFileCollection1 = oFolder1.Files
    
    	For each oFile1 in oFileCollection1
    		If oFile1.DateLastModified < (Date() - iDaysOld) Then
    			oFile1.Delete(True)
    		End If
    	Next
    
    End Sub
    
    Sub DelArchExceptions
    
    	sDirectoryPath2 = sBaseDirectory & "\archive\exceptions\"
    	set oFolder2 = oFSO.GetFolder(sDirectoryPath2)
    	set oFileCollection2 = oFolder2.Files
    
    
    	For each oFile2 in oFileCollection2
    		If oFile2.DateLastModified < (Date() - iDaysOld) Then
    			oFile2.Delete(True)
    		End If
    	Next
    
    End Sub
    
    Sub MovingFiles
    
    		oFSO.MoveFile sBaseDirectory & "\logs\Exceptions-*.*", sBaseDirectory & "\Archive\Exceptions"	
    		oFSO.MoveFile sBaseDirectory & "\logs\Debug-*.*",sBaseDirectory & "\Archive\Debug"		
    		oFSO.MoveFile sBaseDirectory & "\logs\Info-*.*",sBaseDirectory & "\Archive\Info"		
    		oFSO.MoveFile sBaseDirectory & "\logs\OrderAudit-*.*",sBaseDirectory & "\Archive\OrderAudit"		
    	
    End Sub
    
    'Cleanup!
    
    	Set oFSO = Nothing
    	Set oFolder = Nothing
    	Set oFolder1 = Nothing
    	Set oFolder2 = Nothing
    	Set oFileCollection = Nothing
    	Set oFileCollection1 = Nothing
    	Set oFileCollection2 = Nothing
    	Set oFile = Nothing
    	Set oFile1 = Nothing
    	Set oFile2 = Nothing
    	Set sDirectoryPath = Nothing
    	Set sDirectoryPath1 = Nothing
    	Set sDirectoryPath2 = Nothing
Working...
X