Re: batch file scripting
- From: "Niall Litchfield" <niall.litchfield@xxxxxxxxx>
- To: spikey.mcmarbles@xxxxxxxxx
- Date: Sat, 22 Jul 2006 22:37:50 +0100
The script below is vbscript which will do what you want. No add-on's
required (unless you are on an unsupported OS like NT4).
Rem *****************************************
Rem * This script deletes archive log files *
rem * which are more than <iDays> old *
Rem * From archive log directory *
Rem * *
Rem *****************************************
Rem
Rem *****************************************
Rem * Version History: *
Rem * 0.1 Niall Litchfield 29/08/2003 *
Rem *****************************************
' Constants alter if necessary
const iDays = 7 ' Change this to change archive retention period
const arch_dest = "<location of files to delete>"
dim today,arch_date
today = Now()
arch_date = today - iDays
DeleteArchives arch_dest,arch_date
Sub DeleteArchives(strFolder,modDate)
' sub routine to delete archives older than
' modDate. Called twice
Dim fileSystem ' Filesystem Object
Dim folder ' Folder
Dim file ' File Object
' Create the filesystem object
set filesystem = createobject("Scripting.FileSystemObject")
' get the Folder
set folder = fileSystem.GetFolder( strFolder)
' create a file enumerator
For each filename in folder.files
' get file object
set file = fileSystem.GetFile( fileName)
' get date last modified
dateLastModified = file.DateLastModified
' if file is older than NUMBER_OF_DAYS
if dateLastModified < modDate then
fileSystem.DeleteFile (fileName)
end if
next
End Sub
On 7/21/06, Greg Norris <spikey.mcmarbles@xxxxxxxxx> wrote:
On 7/19/06, Steve Perry <sperry@xxxxxxxxxxx> wrote:
>
> that only takes 2 lines :)))
>
> C:\>set f=myfile_%date:~10,4%-%date:~4,2%-%date:~7,2%
> C:\>echo %f%
> myfile_2006-07-19
On a semi-related note, is there any way (using "pure" cmd.exe) to
identify files older than say, 5 days? For example, something similar
to "find . -name "myfile\* -mtime +5".
Unfortunately I'm not allowed to add additional software, so the use
of add-on tools like cygwin/perl/etc. simply isn't an option. :(
--
"I'm too sexy for my code." - Awk Sed Fred.
--
http://www.freelists.org/webpage/oracle-l
--
Niall Litchfield
Oracle DBA
http://www.orawin.info
- References:
- batch file scripting
- From: Joe Smith
- Re: batch file scripting
- From: Jared Still
- Re: batch file scripting
- From: Steve Perry
- Re: batch file scripting
- From: Greg Norris
Other related posts:
- » batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
- » RE: batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
- » Re: batch file scripting
dim today,arch_date
Sub DeleteArchives(strFolder,modDate) ' sub routine to delete archives older than ' modDate. Called twice Dim fileSystem ' Filesystem Object Dim folder ' Folder Dim file ' File Object
On 7/19/06, Steve Perry <sperry@xxxxxxxxxxx> wrote: > > that only takes 2 lines :))) > > C:\>set f=myfile_%date:~10,4%-%date:~4,2%-%date:~7,2% > C:\>echo %f% > myfile_2006-07-19
On a semi-related note, is there any way (using "pure" cmd.exe) to identify files older than say, 5 days? For example, something similar to "find . -name "myfile\* -mtime +5".
Unfortunately I'm not allowed to add additional software, so the use of add-on tools like cygwin/perl/etc. simply isn't an option. :(
-- "I'm too sexy for my code." - Awk Sed Fred. -- http://www.freelists.org/webpage/oracle-l
- batch file scripting
- From: Joe Smith
- Re: batch file scripting
- From: Jared Still
- Re: batch file scripting
- From: Steve Perry
- Re: batch file scripting
- From: Greg Norris