home *** CD-ROM | disk | FTP | other *** search
- ############################################################################
- #
- # File: dosfiles.icn
- #
- # Subject: Procedures to get MS-DOS file names
- #
- # Author: Paul Abrahams
- #
- # Date: September 24, 1990
- #
- ###########################################################################
- #
- # dosfiles(pfn) accepts a DOS filename possibly containing wildcards.
- # The filename can also include a drive letter and path.
- # If the filename ends in "\" or ":", "*.*" is appended.
- #
- # The result sequence is a sequence of the filenames corresponding to pfn.
- #
- ############################################################################
- #
- # Requires: MS-DOS extensions
- #
- ############################################################################
-
- procedure dosfiles(pfn)
- local asciiz, fnr, prefix, k, name
- local ds, dx, result, fnloc, string_block
-
- # Get Disk Transfer Address; filename locn is 30 beyond that.
-
- result := Int86([16r21, 16r2f00] ||| list(7,0))
- fnloc := 16 * result[8] + result[3]+ 30
-
- # Get the generalized filename.
-
- fnr := reverse(pfn)
- k := upto("\\:", fnr) | *fnr + 1
- prefix := reverse(fnr[k:0])
- name := "" ~== reverse(fnr[1:k]) | "*.*"
-
- # Get the first file in the sequence.
-
- asciiz := prefix || name || "\x00"
- Poke(string_block := GetSpace(*asciiz), asciiz)
- ds := string_block / 16
- dx := string_block % 16
- result := Int86([16r21, 16r4e00, 0, 0, dx, 0, 0, 0, ds])
- case result[2] of {
- 0 : {}
- 18 : fail
- default : stop("i/o error ", result[2])
- }
- suspend prefix || extract_name(fnloc)
-
- # Get the remaining files in the sequence.
-
- while Int86([16r21, 16r4f00, 0, 0, 0, 0, 0, 0, 0])[2] = 0 do
- suspend prefix || extract_name(fnloc)
- end
-
- procedure extract_name(fnloc)
- local asciiz
- asciiz := Peek(fnloc, 13)
- return asciiz[1:upto("\x00", asciiz)]
- end
-