PROCEDURE (ram$detuf) detach_unique_files, detuf (
  catalog, c: file = :$local
  status)

" PURPOSE:
"   Detach uniquely named files.
" DESIGN:
"   Delete temporary files and detach permanent files, the origin of unique file names can be important.
" NOTES:
"   Use CYCLE statement to quickly skip those file names which do not fit the unique name pattern.

  VAR
    detach_status : status
    file_string : string 1..31
    files : list 0..$max_list of file = $catalog_contents(catalog, include_files, paths)
  VAREND

" Process every file name in the catalog for unique name patterns. Multiple cycles are not checked.
  FOR EACH file IN files DO
    file_string=$path(file, last)
    CYCLE WHEN $size(file_string)< 31
    CYCLE WHEN file_string(1, 1) <> '$'
    CYCLE WHEN file_string(11, 1) <> 'S' OR file_string(16, 1) <> 'D' OR file_string(25, 1) <> 'T'
    IF $file(file, permanent) THEN
      $system.detach_file file status=detach_status
      IF detach_status.normal THEN
        put_line ('   DETACHED FILE '//file) output=$response
      IFEND
    ELSE
      $system.delete_file file status=detach_status
      IF detach_status.normal THEN
        put_line ('   DELETED FILE  '//file) output=$response
      IFEND
    IFEND
  FOREND

PROCEND detach_unique_files
