home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / DOSFILES.ICN < prev    next >
Text File  |  1991-07-13  |  2KB  |  65 lines

  1. ############################################################################
  2. #
  3. #   Name:    dosfiles.icn
  4. #
  5. #   Title:   Get MS-DOS file names.
  6. #
  7. #   Author:  Paul Abrahams
  8. #
  9. #   Date:    September 24, 1990
  10. #
  11. ############################################################################
  12. #  dosfiles(pfn) accepts a DOS filename possibly containing wildcards.
  13. #  The filename can also include a drive letter and path.
  14. #  If the filename ends in "\" or ":", "*.*" is appended.
  15. #  The result sequence is a sequence of the filenames corresponding to pfn.
  16. ############################################################################
  17. #
  18. #  Requires: MS-DOS extensions
  19. #
  20. ############################################################################
  21.  
  22. procedure dosfiles(pfn)
  23.    local asciiz, fnr, prefix, k, name
  24.    local ds, dx, result, fnloc, string_block
  25.  
  26. # Get Disk Transfer Address; filename locn is 30 beyond that.
  27.  
  28.    result := Int86([16r21, 16r2f00] ||| list(7,0))
  29.    fnloc := 16 * result[8] + result[3]+ 30
  30.  
  31. # Get the generalized filename.
  32.  
  33.    fnr := reverse(pfn)
  34.    k := upto("\\:", fnr) | *fnr + 1
  35.    prefix := reverse(fnr[k:0])
  36.    name := "" ~== reverse(fnr[1:k]) | "*.*"
  37.  
  38. # Get the first file in the sequence.
  39.  
  40.    asciiz := prefix || name || "\x00"
  41.    Poke(string_block := GetSpace(*asciiz), asciiz)
  42.    ds := string_block / 16
  43.    dx := string_block % 16
  44.    result := Int86([16r21, 16r4e00, 0, 0, dx, 0, 0, 0, ds])
  45.    case result[2] of {
  46.       0 : {}
  47.       18 : fail
  48.       default : stop("i/o error ", result[2])
  49.       }
  50.    suspend prefix || extract_name(fnloc)
  51.  
  52. # Get the remaining files in the sequence.
  53.  
  54.    while Int86([16r21, 16r4f00, 0, 0, 0, 0, 0, 0, 0])[2] = 0 do
  55.       suspend prefix || extract_name(fnloc)
  56. end
  57.  
  58. procedure extract_name(fnloc)
  59.    local asciiz
  60.    asciiz := Peek(fnloc, 13)
  61.    return asciiz[1:upto("\x00", asciiz)]
  62. end
  63.