I have an automated process that pumps out a summary file from a large system every few minutes. If there was no activity, it pumps out a blank (0K) file. I would like to write a script to search a specified directory (p:\archive) and delete all blank files. If there were transactions during the period of time then the file will be at least 2K in size. If I can get a script to do this, then I will schedule it to run every so often to clean out the old garbage. The script would be able to run either on an XP Pro machine or on a W2003 Server.
I have something but it does not seem to work and I am just starting out with scripts. What I have so far is:
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objDIR = GetFolder(sDIR)
sDIR="p:\archive"
lSIZE = 0
uSIZE = 1
Set objDIR = GetFolder(sDIR)
GoSubFolders objDIR
Sub MainSub (objDIR)
For Each efile in ObjDIR.Files
If lSIZE = Null and uSIZE = Null Then
If efile.Size = 0 Then
DelFile efile
End If
ElseIf lSIZE <> Null and uSIZE = Null Then
If efile.Size < lSIZE Then
DelFile efile
End If
ElseIf lSIZE = NULL and uSIZE <> "" Then
If efile.Size > uSIZE Then
DelFile efile
End If
ElseIf lSIZE = uSIZE Then
If efile.SIZE = lSIZE Then
DelFile efile
End If
Else If efile.Size > lSIZE and efile.Size<uSIZE Then
DelFile efile
End If
End IF
Next
End Sub
Sub GoSubFolders (objDIR)
If objDIR <> "\System Volume Information" Then
ListFiles objDIR
For Each eFolder in objDir.SubFolders
Wscript.Echo eFolder
GoSubFolders eFolder
Next
End If
End Sub
Sub DelFile(sFILE)
On Error Resume Next
FSO.DeleteFile sFILE, True
If Err.Number <> 0 Then
Wscript.Echo "Error deleting file: " & sfile
End If
End Sub
Sub ListFiles (objDIR)
For Each efile in objDIR.Files
Wscript.Echo efile
Next
End Sub
Thanks in advance for all help!
I have something but it does not seem to work and I am just starting out with scripts. What I have so far is:
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objDIR = GetFolder(sDIR)
sDIR="p:\archive"
lSIZE = 0
uSIZE = 1
Set objDIR = GetFolder(sDIR)
GoSubFolders objDIR
Sub MainSub (objDIR)
For Each efile in ObjDIR.Files
If lSIZE = Null and uSIZE = Null Then
If efile.Size = 0 Then
DelFile efile
End If
ElseIf lSIZE <> Null and uSIZE = Null Then
If efile.Size < lSIZE Then
DelFile efile
End If
ElseIf lSIZE = NULL and uSIZE <> "" Then
If efile.Size > uSIZE Then
DelFile efile
End If
ElseIf lSIZE = uSIZE Then
If efile.SIZE = lSIZE Then
DelFile efile
End If
Else If efile.Size > lSIZE and efile.Size<uSIZE Then
DelFile efile
End If
End IF
Next
End Sub
Sub GoSubFolders (objDIR)
If objDIR <> "\System Volume Information" Then
ListFiles objDIR
For Each eFolder in objDir.SubFolders
Wscript.Echo eFolder
GoSubFolders eFolder
Next
End If
End Sub
Sub DelFile(sFILE)
On Error Resume Next
FSO.DeleteFile sFILE, True
If Err.Number <> 0 Then
Wscript.Echo "Error deleting file: " & sfile
End If
End Sub
Sub ListFiles (objDIR)
For Each efile in objDIR.Files
Wscript.Echo efile
Next
End Sub
Thanks in advance for all help!