created a script to delete files ie) *.jpg files in folder and log entrys,
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

Re: Basic script help please by Torgeir

Torgeir
Thu Oct 07 04:54:12 CDT 2004

Monkey wrote:
> created a script to delete files ie) *.jpg files in folder and log entrys,
> 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
> [snip]
Hi

Note that if you want to delete files from a file collection returned
from the File System Object, you should *never* do this when still
looping through the collection. The collection may get mixed up with
unpredictable results. Create an array of the file paths first to
avoid this.

In the article below there is a WSH script (vbscript) by Michael
Harris that deletes files x days old in a specific folder (and
optionally all subfolders), using an array of the file paths.

Newsgroups: microsoft.public.scripting.wsh
Date: 2002-10-07 08:12:33 PST
http://groups.google.com/groups?selm=3DA1A19B.DF9B06D7%40hydro.com



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Re: Basic script help please by Monkey

Monkey
Fri Oct 08 08:01:02 CDT 2004

excellant, thanks that seemed to work



"Torgeir Bakken (MVP)" wrote:

> Monkey wrote:
> > created a script to delete files ie) *.jpg files in folder and log entrys,
> > 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
> > [snip]
> Hi
>
> Note that if you want to delete files from a file collection returned
> from the File System Object, you should *never* do this when still
> looping through the collection. The collection may get mixed up with
> unpredictable results. Create an array of the file paths first to
> avoid this.
>
> In the article below there is a WSH script (vbscript) by Michael
> Harris that deletes files x days old in a specific folder (and
> optionally all subfolders), using an array of the file paths.
>
> Newsgroups: microsoft.public.scripting.wsh
> Date: 2002-10-07 08:12:33 PST
> http://groups.google.com/groups?selm=3DA1A19B.DF9B06D7%40hydro.com
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx
>