Re: Script to delete files

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"dude" <secrect@xxxxxxxx> wrote in message
news:OYjx6WIiFHA.3540@xxxxxxxxxxxxxxxxxxxxxxx
> Im trying to make a simple script, that can delete some files older than
30
> days,
> but im not soure where to start.
> I hope someone can help me using the filesystemobject.

I use just such a script. I have some log files that I have to keep for a
week.

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = FSO.GetFolder("D:\Resource\Data\logs")
For Each File in oFolder.Files
If DateDiff("d", CDate(File.DateLastModified), Now()) > 7 Then
FSO.DeleteFile File
Next
Set oFolder = Nothing
Set FSO = Nothing
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I schedule it to run every day using the AT scheduler:

AT 05:00 /INTERACTIVE /EVERY:S,M,T,W,Th,F,Sa "R:\Delete Files"

Just customize the path & DateDiff in the above script to meet your needs.
Consider that the script as it is currently written affects all files in the
given directory.


.



Relevant Pages

  • Re: problem using FileSystemObject
    ... > When I came to the FileSystemObject I found IIS hangs on OpenTextFile. ... > I'm using the Script Debugger and executing one command at a time and it ... Set fso = Server.CreateObject ... > ' fails here ...
    (microsoft.public.inetserver.asp.general)
  • Re: Running FTP script and waiting for answer...can I set "timeout"
    ... Try this command to change default script engine to cscript from wscript ... I'm running ftp "run command" every 2 minuteto lookup new ... I can give you a copy of my script for you to scan... ... Set Fso = Wscript.Createobject ...
    (microsoft.public.scripting.vbscript)
  • Re: Running FTP script and waiting for answer...can I set "timeout"
    ... Try this command to change default script engine to cscript from wscript ... I'm running ftp "run command" every 2 minuteto lookup new ... I can give you a copy of my script for you to scan... ... Set Fso = Wscript.Createobject ...
    (microsoft.public.scripting.vbscript)
  • Re: Task Scheduler IGNORES duration
    ... task stopped triggering based on "start every minute" for a "duration ... Btw my original backup check script ... Set fso = CreateObject ...
    (microsoft.public.windows.server.general)
  • Re: Re: Setting the &gt;&gt;homeDirectory&lt;&lt; field in CSVDE
    ... > modify AD. ADUC, like i said, does the same thing, but has ... > and assigns the proper permissions for the user. ... My friend wrote an ASP script that interfaces with AD and creates the ... set fso = server.CreateObject ...
    (microsoft.public.win2000.active_directory)