Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have to write a script in a command file to delete some files which are older than 14 days than the date entered by user. The problem is that the dates to delete are not dependant on the date of creation but by the date given in the filename e.g. DEB_31082002.FIL. So in this case I would want to delete anything older than 17th August 2002. This is very tricky since I have to consider both month and year rollovers. Any ideas?

Not so difficult if you let VMS calculate the boundary. A basic commandfile would look something like :
$!
$! ask the date in VMS format DD-MMM-YYYY
$!
$ read sys$command /prompt="date " askdate
$ deldate = f$cvtime("''askdate'-14-","COMPARISON","DATE")
$!
$! Loop through files looking for candidates
$!
$findfile:
$ fullname = f$search("deb*.fil;*")
$ if fullname .eqs. "" then goto endfiles
$ filename = f$parse(fullname,,,"NAME","SYNTAX_ONLY")
$ filedate = f$extract(8,4,filename) + "-" + -
f$extract(6,2,filename) + "-" + -
f$extract(4,2,filename)
$ sh sym filedate
$ if filedate .lts. deldate
$ then
$ write sys$output "This file will be deleted ", filename
$! delete /log 'fullname'
$ endif
$ goto findfile
$endfiles:
$ exit

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |