Hello,
I am trying to do a simple console app to delete older files; it does
not work and the debugger does not see the mistake.
Any help would be greatly appreciated.




Sub Main()


On Error Resume Next
Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oFileCollection
Dim oFile
Dim iDaysOld
Dim todaysdate




todaysdate = Now()
iDaysOld = 1
oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = ("\\vs1\c:\temp")
oFolder = oFSO.GetFolder(sDirectoryPath)
oFileCollection = oFolder.Files

For Each oFile In oFileCollection
If oFile.DateLastModified < (todaysdate) - (iDaysOld) Then
oFile.Delete(True)
End If
Next

'Clean up
oFSO = Nothing
oFolder = Nothing
oFileCollection = Nothing
oFile = Nothing


End Sub

Re: VBScript compilation error for console app by Richard

Richard
Thu Nov 09 22:10:21 CST 2006

First, I would recommend removing "On Error Resume Next" so you get error
messages. You have no hope of troubleshooting otherwise.

The variables oFSO, oFolder, and oFileCollection are objects, so you must
create them with a "Set" statement. Use:
==========
Set oFSO = CreateObject("Scripting.FileSystemObject")
...
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files
...
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Hulicat" <dennis_A_white@yahoo.com> wrote in message
news:1163122185.594446.317660@m73g2000cwd.googlegroups.com...
> Hello,
> I am trying to do a simple console app to delete older files; it does
> not work and the debugger does not see the mistake.
> Any help would be greatly appreciated.
>
>
>
>
> Sub Main()
>
>
> On Error Resume Next
> Dim oFSO
> Dim sDirectoryPath
> Dim oFolder
> Dim oFileCollection
> Dim oFile
> Dim iDaysOld
> Dim todaysdate
>
>
>
>
> todaysdate = Now()
> iDaysOld = 1
> oFSO = CreateObject("Scripting.FileSystemObject")
> sDirectoryPath = ("\\vs1\c:\temp")
> oFolder = oFSO.GetFolder(sDirectoryPath)
> oFileCollection = oFolder.Files
>
> For Each oFile In oFileCollection
> If oFile.DateLastModified < (todaysdate) - (iDaysOld) Then
> oFile.Delete(True)
> End If
> Next
>
> 'Clean up
> oFSO = Nothing
> oFolder = Nothing
> oFileCollection = Nothing
> oFile = Nothing
>
>
> End Sub
>



Re: VBScript compilation error for console app by dNagel

dNagel
Thu Nov 09 22:31:03 CST 2006

Dim strPath = "C:\Temp\"
Dim iDays = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
For Each objItem In objFolder.Files
If objItem.DateLastModified < date() - iDays then
objFSO.DeleteFile(strPath & objitem.Name)
End If
Next


D.

Hulicat wrote:
> Hello,
> I am trying to do a simple console app to delete older files; it does
> not work and the debugger does not see the mistake.
> Any help would be greatly appreciated.
>
>
>
>
> Sub Main()
>
>
> On Error Resume Next
> Dim oFSO
> Dim sDirectoryPath
> Dim oFolder
> Dim oFileCollection
> Dim oFile
> Dim iDaysOld
> Dim todaysdate
>
>
>
>
> todaysdate = Now()
> iDaysOld = 1
> oFSO = CreateObject("Scripting.FileSystemObject")
> sDirectoryPath = ("\\vs1\c:\temp")
> oFolder = oFSO.GetFolder(sDirectoryPath)
> oFileCollection = oFolder.Files
>
> For Each oFile In oFileCollection
> If oFile.DateLastModified < (todaysdate) - (iDaysOld) Then
> oFile.Delete(True)
> End If
> Next
>
> 'Clean up
> oFSO = Nothing
> oFolder = Nothing
> oFileCollection = Nothing
> oFile = Nothing
>
>
> End Sub
>
>

Re: VBScript compilation error for console app by Hulicat

Hulicat
Fri Nov 10 09:04:37 CST 2006

Thanks for the responses!
I appreciate it.

Regards,
H
dNagel wrote:
> Dim strPath = "C:\Temp\"
> Dim iDays = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder(strPath)
> For Each objItem In objFolder.Files
> If objItem.DateLastModified < date() - iDays then
> objFSO.DeleteFile(strPath & objitem.Name)
> End If
> Next
>
>
> D.
>
> Hulicat wrote:
> > Hello,
> > I am trying to do a simple console app to delete older files; it does
> > not work and the debugger does not see the mistake.
> > Any help would be greatly appreciated.
> >
> >
> >
> >
> > Sub Main()
> >
> >
> > On Error Resume Next
> > Dim oFSO
> > Dim sDirectoryPath
> > Dim oFolder
> > Dim oFileCollection
> > Dim oFile
> > Dim iDaysOld
> > Dim todaysdate
> >
> >
> >
> >
> > todaysdate = Now()
> > iDaysOld = 1
> > oFSO = CreateObject("Scripting.FileSystemObject")
> > sDirectoryPath = ("\\vs1\c:\temp")
> > oFolder = oFSO.GetFolder(sDirectoryPath)
> > oFileCollection = oFolder.Files
> >
> > For Each oFile In oFileCollection
> > If oFile.DateLastModified < (todaysdate) - (iDaysOld) Then
> > oFile.Delete(True)
> > End If
> > Next
> >
> > 'Clean up
> > oFSO = Nothing
> > oFolder = Nothing
> > oFileCollection = Nothing
> > oFile = Nothing
> >
> >
> > End Sub
> >
> >


Re: VBScript compilation error for console app by Fosco

Fosco
Fri Nov 10 20:00:00 CST 2006

"Hulicat"
> I am trying to do a simple console app to delete older files; it does
> not work and the debugger does not see the mistake.


'''' ON ERROR RESUME NEXT

todaysdate = Now()
Msgbox Now()
iDaysOld = 1

SET oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = ("c:\temp")
SET oFolder = oFSO.GetFolder(sDirectoryPath)
SET oFileCollection = oFolder.Files

For Each oFile In oFileCollection
Msgbox oFile.DateLastModified
Msgbox oFile.DateLastModified < (todaysdate) - (iDaysOld)
If oFile.DateLastModified < (todaysdate) - (iDaysOld) Then
Msgbox oFile.name

oFile.Delete(True)
End If
Next


--
Fosco