Volkmaniac
Technical User
This is a script I took off of Is there anyway I can alter this to delete the latest files by date as opposed to just deleting the newest? I tried changing $FLTIME to $FDATE but that didn't work. I need to delete all the newest files to a directory from the most current date.
proc main
long lDate = 0 ;Hold long value representing date/time of file
string sFname ;Contains full filespec of currently-latest file
if findfirst "S:\Client Services\LETTERS\*.*" "NRHSA" ;Search all files in specified directory
sFname = $FILESPEC ;Set latest file to that of initial file
lDate = $FLTIME ;Set time/date to that of initial file
while findnext ;Continue searching hile more files remain
if $FLTIME <= lDate ;If next file is older than current latest file
lDate = $FLTIME ;Set time/date to that of older-found file
delfile sFname ;Delete previously-latest file
sFname = $FILESPEC ;Set latest file variable to the older-found file
else ;If file was not older...
delfile $FILESPEC ;Then delete newly-found file
endif
endwhile
else ;No files found in specified directory
usermsg "No files found!"
endif
endproc
proc main
long lDate = 0 ;Hold long value representing date/time of file
string sFname ;Contains full filespec of currently-latest file
if findfirst "S:\Client Services\LETTERS\*.*" "NRHSA" ;Search all files in specified directory
sFname = $FILESPEC ;Set latest file to that of initial file
lDate = $FLTIME ;Set time/date to that of initial file
while findnext ;Continue searching hile more files remain
if $FLTIME <= lDate ;If next file is older than current latest file
lDate = $FLTIME ;Set time/date to that of older-found file
delfile sFname ;Delete previously-latest file
sFname = $FILESPEC ;Set latest file variable to the older-found file
else ;If file was not older...
delfile $FILESPEC ;Then delete newly-found file
endif
endwhile
else ;No files found in specified directory
usermsg "No files found!"
endif
endproc