RE: Script to delete files and log entry

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Monkey (Monkey_at_discussions.microsoft.com)
Date: 09/29/04


Date: Wed, 29 Sep 2004 00:39:05 -0700

anyone??
please

"Monkey" wrote:

> created a script to do this, but must be missing something as it doesnt log
> anything and doesnt delete anything anymore. It had it deleting at one stage,
> but must have changed something and not sure what.
> Any ideas clever people?
>
> Path1 = "C:\Documents and Settings\REMOTEINSTALL\My Documents\My
> Pictures\QuickCam\Album\Motion Images\Security Videos"
>
> Dim objFSO 'File System Object - connection to file system
> Dim oFolder 'holds path to image folder
> Dim oFile 'variable for each file in folder
> Dim logfile 'holds path to the log file
> Dim objFile 'used by OpenTextFile command to allow writing to
> file
> Const ForWriting = 2
> Const ForAppending = 8
> logfile = "C:\Delete Files Script\log.txt"
>
> Set objFSO = Createobject("Scripting.FileSystemObject")
>
> Set oFolder = objFSO.GetFolder(Path1)
>
> For Each oFile In oFolder.Files
>
> If DateDiff("d", oFile.DateCreated,Now) > 14 Then
> oFile.Delete
> wscript.Echo "this file was deleted " & oFile.Name
>
> If objFSO.FileExists(logfile) Then
> Set objFile = objFSO.OpenTextFile(logfile, ForAppending)
> objFile.Write oFile.Name
> Else
>
> Set objFile = objFSO.OpenTextFile(logfile, ForWriting)
> objFile.Write oFile.Name
> objFile.Close
>
> 'WScript.Echo "file " & oFile.Name
> 'objFile.WriteLine oFile.Name & Now 'Now command writes data/time
> 'objFile.Close
> 'WScript.Echo "Log file ammended"
>
> End If
> End If
>
> Next



Relevant Pages