Jump to content

Script needed to Delete Files in a Directory Based on Date


Recommended Posts

Guest adaher008 via WinServerKB.com
Posted

Hi -

 

I have a folder that contains about 250,000 zipped files. Windows explorer is

having tremendous difficulty opening such folder, even when it displays

results (after 10 or so minutes) it hangs after I even highlight any files

for deletion. a lot of these files go back to 2006 and 2007.

 

I kindly NEED a DOS batch file or some script that I would enable me to

delete the files that are older than may 2008 (In other words delete files

between May 2008 and May 2006).

 

Thank You, and your efforts are much appreciated in advance.

 

wiseteufel

 

--

Message posted via WinServerKB.com

http://www.winserverkb.com/Uwe/Forums.aspx/windows-server/200809/1

  • Replies 2
  • Created
  • Last Reply
Guest Pegasus \(MVP\)
Posted

Re: Script needed to Delete Files in a Directory Based on Date

 

 

"adaher008 via WinServerKB.com" <u38920@uwe> wrote in message

news:89fd5ee3fa192@uwe...

> Hi -

>

> I have a folder that contains about 250,000 zipped files. Windows explorer

> is

> having tremendous difficulty opening such folder, even when it displays

> results (after 10 or so minutes) it hangs after I even highlight any files

> for deletion. a lot of these files go back to 2006 and 2007.

>

> I kindly NEED a DOS batch file or some script that I would enable me to

> delete the files that are older than may 2008 (In other words delete files

> between May 2008 and May 2006).

>

> Thank You, and your efforts are much appreciated in advance.

>

> wiseteufel

>

> --

> Message posted via WinServerKB.com

> http://www.winserverkb.com/Uwe/Forums.aspx/windows-server/200809/1

>

 

Try this script, written by Tom Lavedas and myself. It will delete files

older than 120 days.

sFolder = "d:\temp\"

iMaxAge = 120

Set oFSO = CreateObject("Scripting.FileSystemObject")

If oFSO.FolderExists(sFolder) Then

for each oFile in oFSO.GetFolder(sFolder).Files

If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then

wscript.echo "Deleting oFile.Name"

' oFile.Delete

End If

next

End If

 

Run the script in its current form. When you're happy with the result,

activate it by removing the single quote from this line:

' oFile.Delete

Guest T Lavedas
Posted

Re: Script needed to Delete Files in a Directory Based on Date

 

On Sep 10, 4:56 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:

> "adaher008 via WinServerKB.com" <u38920@uwe> wrote in messagenews:89fd5ee3fa192@uwe...

>

>

>

> > Hi -

>

> > I have a folder that contains about 250,000 zipped files. Windows explorer

> > is

> > having tremendous difficulty opening such folder, even when it displays

> > results (after 10 or so minutes) it hangs after I even highlight any files

> > for deletion. a lot of these files go back to 2006 and 2007.

>

> > I kindly NEED a DOS batch file or some script that I would enable me to

> > delete the files that are older than may 2008 (In other words delete files

> > between May 2008 and May 2006).

>

> > Thank You, and your efforts are much appreciated in advance.

>

> > wiseteufel

>

> > --

> > Message posted via WinServerKB.com

> >http://www.winserverkb.com/Uwe/Forums.aspx/windows-server/200809/1

>

> Try this script, written by Tom Lavedas and myself. It will delete files

> older than 120 days.

> sFolder = "d:\temp\"

> iMaxAge = 120

> Set oFSO = CreateObject("Scripting.FileSystemObject")

> If oFSO.FolderExists(sFolder) Then

>  for each oFile in oFSO.GetFolder(sFolder).Files

>    If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then

>     wscript.echo "Deleting oFile.Name"

> '    oFile.Delete

>    End If

>  next

> End If

>

> Run the script in its current form. When you're happy with the result,

> activate it by removing the single quote from this line:

> '    oFile.Delete

 

Tiny typo in the echo line, it should read ...

 

wscript.echo "Deleting", oFile.Name

 

Tom Lavedas

===========

http://members.cox.net/tglbatch/wsh/


×
×
  • Create New...