NT tool to delete files by date?
Chaps,
Anyone know of anything in the resource kit or elsewhere to delete files older than a given date or after a given number of days?
Robocopy lets me copy stuff to another folder then delete it, but it's not quite right.
Cheers
Anyone know of anything in the resource kit or elsewhere to delete files older than a given date or after a given number of days?
Robocopy lets me copy stuff to another folder then delete it, but it's not quite right.
Cheers
Scooby Regular
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
this might do what you want?? cant you just do a search in windows then delete the results...
'
' Script to delete files older than a given number of days.
'
' WARNING: Files deleted with this program could not be recovered. They don't even get to Recycle Bin.
' Use at your own risk.
'
' (C) Copyright, 2002. Ferran Foz. Barcelona, Spain. ferran@ostres.com
'
' You may copy and distribute without changing the copyright notice.
'
'
Set StdOut = WScript.StdOut
Main
Sub Main()
'
' DropOldFiles
' folderspec - Folder where you want to delete files
' logfile - File where logfile will be generated.
' days - Number of days to keep files.
'
Call DropOldFiles("C:\zzTEMP\","C:\TEMP\LOG.TXT", 100)
End Sub
Sub DropOldFiles(folderspec, logfile, days)
Dim fso,f,f1,s,fi, cnt, tot
StdOut.WriteLine "Starting DropOldFiles..."
LogOpen(logfile)
cnt = 0
tot = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
If DateDiff ("d",f1.DateLastModified, Now ) > days Then
LogWrite f1.name & " DateLastModified:" & f1.DateLastModified & " DaysOld:" & DateDiff ("d",f1.DateLastModified, Now )
fso.DeleteFile (folderspec & f1.name)
cnt = cnt + 1
End If
tot = tot + 1
Next
LogWrite "--------------------------------------------------------------"
LogWrite " Processed " & tot & " file(s). Deleted " & cnt & " file(s)."
LogWrite "--------------------------------------------------------------"
LogClose
StdOut.WriteLine "Ending DropOldFiles..."
End Sub
'
' ************************************************** ***************************************
'
'
' Write to the Logfile
'
Dim LogFile
Sub LogWrite (Text)
LogFile.WriteLine "[" & Now & "] " & Text
End Sub
Sub LogClose ()
LogFile.Close
Set Logfile=nothing
End Sub
Sub LogOpen (LogPath)
Dim fso, f1
Const ForAppend = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set LogFile = fso.OpenTextFile(LogPath, ForAppend, True)
Set fso = nothing
End Sub
David
'
' Script to delete files older than a given number of days.
'
' WARNING: Files deleted with this program could not be recovered. They don't even get to Recycle Bin.
' Use at your own risk.
'
' (C) Copyright, 2002. Ferran Foz. Barcelona, Spain. ferran@ostres.com
'
' You may copy and distribute without changing the copyright notice.
'
'
Set StdOut = WScript.StdOut
Main
Sub Main()
'
' DropOldFiles
' folderspec - Folder where you want to delete files
' logfile - File where logfile will be generated.
' days - Number of days to keep files.
'
Call DropOldFiles("C:\zzTEMP\","C:\TEMP\LOG.TXT", 100)
End Sub
Sub DropOldFiles(folderspec, logfile, days)
Dim fso,f,f1,s,fi, cnt, tot
StdOut.WriteLine "Starting DropOldFiles..."
LogOpen(logfile)
cnt = 0
tot = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
If DateDiff ("d",f1.DateLastModified, Now ) > days Then
LogWrite f1.name & " DateLastModified:" & f1.DateLastModified & " DaysOld:" & DateDiff ("d",f1.DateLastModified, Now )
fso.DeleteFile (folderspec & f1.name)
cnt = cnt + 1
End If
tot = tot + 1
Next
LogWrite "--------------------------------------------------------------"
LogWrite " Processed " & tot & " file(s). Deleted " & cnt & " file(s)."
LogWrite "--------------------------------------------------------------"
LogClose
StdOut.WriteLine "Ending DropOldFiles..."
End Sub
'
' ************************************************** ***************************************
'
'
' Write to the Logfile
'
Dim LogFile
Sub LogWrite (Text)
LogFile.WriteLine "[" & Now & "] " & Text
End Sub
Sub LogClose ()
LogFile.Close
Set Logfile=nothing
End Sub
Sub LogOpen (LogPath)
Dim fso, f1
Const ForAppend = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set LogFile = fso.OpenTextFile(LogPath, ForAppend, True)
Set fso = nothing
End Sub
David
Cheers - That was quick
I'll give it a go, but kinda want to do it in DOS to pipe it back to a file, there must be a command line utility.
It's for copying Wininstall packages from a master build server to all other build server across the network, so I can search and destroy older software and copy out new stuff (there are about 50 build servers).
Cheers
FJ
I'll give it a go, but kinda want to do it in DOS to pipe it back to a file, there must be a command line utility.It's for copying Wininstall packages from a master build server to all other build server across the network, so I can search and destroy older software and copy out new stuff (there are about 50 build servers).
Cheers
FJ
Thread
Thread Starter
Forum
Replies
Last Post



