Task

Walk a given directory and print the names of files matching a given pattern.

(How is "pattern" defined? substring match? DOS pattern? BASH pattern? ZSH pattern? Perl regular expression?)


Note: This task is for non-recursive methods.   These tasks should read a single directory, not an entire directory tree.

Note: Please be careful when running any code presented here.



Related task

   Walk Directory Tree   (read entire directory tree). 


 
        TITLE  DIRWLK - Directory Walker
        SUBTTL PDP-10 Assembly Language (MACRO-10 @ TOPS-20). KJX 2022.
 
        SEARCH MONSYM,MACSYM            ;Get system-call names.
        .REQUIRE SYS:MACREL             ;Macros: TMSG, EJSHLT, etc.
 
        STDAC.                          ;Define standard register names.
 
JFN:    BLOCK 1                         ;Space for JFN (file-handle)
FSPEC:  BLOCK 20                        ;Space for file specification.
FSPECL= <.-FSPEC>*5                     ;Length in chars of file-spec.
 
GO::    RESET%                          ;Initialize process.
        TMSG <Please enter filespec, wildcards are allowed: >
        HRROI T1,FSPEC                  ;Read into FSPEC.
        MOVEI T2,FSPECL                 ;Maximum allowed characters.
        SETZ  T3,                       ;No Ctrl-R prompting.
        RDTTY%                          ;Read string from terminal.
          EJSHLT                        ;  Print error-msg on errors.
 
        MOVX  T1,GJ%OLD!GJ%IFG!GJ%FLG!GJ%SHT  ;Various flags.
        HRROI T2,FSPEC                  ;File specification from above.
        GTJFN%                          ;Get JFN for first matching file.
          EJSHLT                        ;  Print error-msg on errors.
        MOVEM T1,JFN                    ;Save JFN.
 
        DO.
          MOVEI T1,.PRIOU               ;Write to standard-output.
          HRRZ  T2,JFN                  ;JFN from above to decode.
          SETZ  T3,                     ;No flags.
          JFNS%                         ;Decode filename and print it.
            EJSHLT                      ;  Print error-msg on errors.
          TMSG <
>                                       ;Print newline.
          MOVE  T1,JFN                  ;Get JFN into T1.
          GNJFN%                        ;Get next matching file.
            JRST [ HALTF%               ;  Halt program on failure.
                   JRST GO ]
          LOOP.                         ;No error: Do it again.
        ENDDO.
 
        END GO
 