dheerajreddy926
Programmer
Hi All,
The following script is deleting only files in LOGARCHIVE folder leaving the empty folder .I want to delete empty folders even. How can i correct it. More over i get an error when it goes to 2nd path \server\lodarchive sayng path not found .Can people suggest me .
In test3.txt i gave both servers one windows and one AIX .Its failing at AIX server sayn path not found
..................................................................
pathfile = "d:\test3.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Check if the "test2.txt" file exists
If Not objFSO.FileExists(pathfile) Then
MsgBox "The file 'path.txt' does not exits", 1, "Error"
WScript.quit 1
End If
'create a stream to read from file
Set instream = objfso.opentextfile(pathfile)
Do While Not instream.atendofstream
folder = instream.readline
Dim msg
msg = "\\" & folder & "\Siebel\enterprises\siebel_aix\" & folder & "\logarchive"
'Checks if folder path exists
If Not objFSO.FolderExists(msg) Then
msg = "\\" & folder & "\d$\sea77\siebsrvr\LOGARCHIVE"
MsgBox folder & " Path not found, Please enter correct path.", 1, "Error"
WScript.quit 1
End If
Dim startFolder, OlderThanDate
Set startFolder = objFSO.GetFolder(msg)
OlderThanDate = DateAdd("d", -5, Date) ' (adjust as necessary)
DeleteOldFiles startFolder, OlderThanDate
Loop
Function DeleteOldFiles(folderName, BeforeDate)
Dim folder, file, fileCollection, folderCollection, subFolder
Set folder = objFSO.GetFolder(folderName)
Set fileCollection = folder.Files
For Each file In fileCollection
If file.DateLastModified < BeforeDate Then
objFSO.DeleteFile(file.Path)
End If
Next
Set folderCollection = folder.SubFolders
For Each subFolder In folderCollection
DeleteOldFiles subFolder.Path, BeforeDate
Next
End Function
The following script is deleting only files in LOGARCHIVE folder leaving the empty folder .I want to delete empty folders even. How can i correct it. More over i get an error when it goes to 2nd path \server\lodarchive sayng path not found .Can people suggest me .
In test3.txt i gave both servers one windows and one AIX .Its failing at AIX server sayn path not found
..................................................................
pathfile = "d:\test3.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Check if the "test2.txt" file exists
If Not objFSO.FileExists(pathfile) Then
MsgBox "The file 'path.txt' does not exits", 1, "Error"
WScript.quit 1
End If
'create a stream to read from file
Set instream = objfso.opentextfile(pathfile)
Do While Not instream.atendofstream
folder = instream.readline
Dim msg
msg = "\\" & folder & "\Siebel\enterprises\siebel_aix\" & folder & "\logarchive"
'Checks if folder path exists
If Not objFSO.FolderExists(msg) Then
msg = "\\" & folder & "\d$\sea77\siebsrvr\LOGARCHIVE"
MsgBox folder & " Path not found, Please enter correct path.", 1, "Error"
WScript.quit 1
End If
Dim startFolder, OlderThanDate
Set startFolder = objFSO.GetFolder(msg)
OlderThanDate = DateAdd("d", -5, Date) ' (adjust as necessary)
DeleteOldFiles startFolder, OlderThanDate
Loop
Function DeleteOldFiles(folderName, BeforeDate)
Dim folder, file, fileCollection, folderCollection, subFolder
Set folder = objFSO.GetFolder(folderName)
Set fileCollection = folder.Files
For Each file In fileCollection
If file.DateLastModified < BeforeDate Then
objFSO.DeleteFile(file.Path)
End If
Next
Set folderCollection = folder.SubFolders
For Each subFolder In folderCollection
DeleteOldFiles subFolder.Path, BeforeDate
Next
End Function