Guardian Programmer's Guide

Table Of Contents
Manipulating File Names
Guardian Programmer’s Guide 421922-014
13 - 39
Manipulating File Names: An Example
!------------------------------------------------------------
! Procedure to find all file names that match a given pattern
! and print each file name.
!------------------------------------------------------------
PROC FIND^FILES(PATTERN,LENGTH);
INT LENGTH;
STRING .PATTERN;
BEGIN
INT SEARCH^ID; !identifies a search
STRING .NAME[0:MAXLEN - 1]; !found file-name string
INT NAMELEN; !length of found file
! name
! Set up the search pattern:
ERROR := FILENAME_FINDSTART_(SEARCH^ID,
PATTERN:LENGTH);
IF ERROR <> 0 THEN CALL FILE^ERRORS(ERROR);
! Loop until pattern ranges exhausted:
WHILE ERROR <> 1 DO
BEGIN
! Find the next file name that matches pattern:
ERROR := FILENAME_FINDNEXT_(SEARCH^ID,
NAME:MAXLEN,
NAMELEN);
IF ERROR > 1 THEN CALL FILE^ERRORS(ERROR)
! Write matching file name to output file:
ELSE CALL PRINT^NAME(NAME,NAMELEN);
END;
! Release resources held by search:
ERROR := FILENAME_FINDFINISH_(SEARCH^ID);
IF ERROR <> 0 THEN CALL FILE^ERRORS(ERROR);
END;