PROCEDURE (ram$delefc) delete_extra_file_cycles, delefc (
  file, files, f: list of file = $required
  retain, r: integer 0..999 = 1
  status)

" PURPOSE:
"   Delete extra cycles of a file.
" DESIGN:
"   Delete all extra cycles of a file which so that only the RETAINed number remain.
" NOTES:
"   Reverse the list returned by $file_cycles to arrange the paths in low to high cycle number order.

  VAR
    cycles : list of file
    delete_status : status
  VAREND

  FOR EACH filename IN files DO " process the list of file names "
    cycles=$reverse($file_cycles(filename, paths))
    FOR low_cycle = 1 TO ($size(cycles) - retain) DO
      $system.delete_file cycles(low_cycle) status=delete_status
      IF delete_status.normal THEN
        put_line ('   DELETED FILE    '//cycles(low_cycle)) output=$response
      IFEND
    FOREND
  FOREND

PROCEND delete_extra_file_cycles
