home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / HISOFT.LZH / HISOFT_B.MSA / EXAMPLES / DIR2STR.BAS < prev    next >
BASIC Source File  |  1991-10-08  |  1KB  |  53 lines

  1. ' this is an example of GEMDOS library usage. ╜ HiSoft 1987
  2. ' the sub-program copies the filenames of files in the given directory
  3. ' into a string
  4. '
  5. ' SCS
  6. '
  7. ' updated for version 2 Oct 91 djn
  8.  
  9. REM $option v                                    'variable checks on
  10. REM $option #+                                    'No FNs in libraries
  11. DEFINT a-z
  12. LIBRARY "gemdos"
  13.  
  14. DIM SHARED dta(22)                                'our DTA
  15.  
  16.  
  17. DO                                                'the main program
  18.     INPUT path$
  19.     IF LEN(path$)=0 THEN STOP -1                'just hit return to quit
  20.     dirstr$=""
  21.     dir2str path$,dirstr$
  22.     PRINT dirstr$
  23. LOOP
  24.  
  25. 'returns in targstr$ a list of files
  26. SUB dir2str(BYVAL pathstr$,targstr$)
  27. STATIC isitthere,olddta&,addr&,hold
  28.  
  29.     olddta&=fgetdta&                            'get the old dta
  30.  
  31.     fsetdta VARPTR(dta(0))                        'this is where we want it
  32.  
  33.     isitthere=fsfirst(pathstr$,0)                'look for the file
  34.  
  35.     IF isitthere>=0 THEN                        'some files available
  36.  
  37.         DO
  38.             addr&=VARPTR(dta(15))
  39.             DO                                    'look for null byte
  40.                 hold=PEEKB(addr&)
  41.                 IF hold=0 THEN EXIT LOOP
  42.                 targstr$=targstr$+CHR$(hold)
  43.                 INCR addr&
  44.             LOOP
  45.  
  46.             targstr$=targstr$+CHR$(13)+CHR$(10)        'add cr-lf
  47.  
  48.             isitthere=fsnext
  49.         LOOP UNTIL  isitthere<0                     'is there another file
  50.     END IF
  51.     fsetdta olddta&                                'if not restore dta and exit
  52. END SUB
  53.