home *** CD-ROM | disk | FTP | other *** search
- Title Subprogram to do file directory searches
- Page 60,130
- ; Created 10-17-1987 k. murray
- ;
- Cseg Segment byte public 'Code'
- Assume Cs:Cseg,Ds:nothing,Es:nothing
- ;
- ; Define in program:
- ; Sub FindFirst DirMask$,RetFile$,Er% External "Dsearch.com"
- ; Sub FindNext RetFile$,Er% External "" 3
- ;
- Start:
- Jmp FindFirst
- Jmp FindNext
- ;
- ; Find first file name that matches directory mask
- ; Stack Frame:
- ; Bp+10 Desc. No. of DirMask$
- ; Bp+8 Desc. No. of RetFile$
- ; Bp+6 Adr. of Er%
- ; Bp+4 Return Segment
- ; Bp+2 Return Offset
- ; Bp+0 Saved Bp
- FindFirst Proc Far
- Push Bp
- Mov Bp,Sp
- Call SetDta ; Set DTA to our area
- Mov Ax,[Bp+10] ; get DirMask$ string Desc #
- Shl Ax,1
- Shl Ax,1
- Mov Bx,Ax
- Mov Es,Ds:[6] ; Segment of string desc's
- Push Ds
- Mov Ds,Es:[Bx+2] ; put segment in Ds
- Mov Dx,2 ; offset is always 2
- Mov Bx,Es:[Bx] ; Put length in Bx
- Push [Bx+2] ; Save word after string
- Mov byte ptr [Bx+2],0 ; put null at end of string
- Push Bx
- Sub Cx,Cx ; Atribute is zero
- Mov Ah,4eh
- Int 21h ; do directory search
- Pop Bx
- Pop [Bx+2] ; restore word after name
- Pop Ds ; restore data segment
- Jc FindFirst02 ; error
- Mov Bx,[Bp+6]
- Sub Ax,Ax
- Mov [Bx],Ax ; Zero error code
- Mov Ax,[Bp+8] ; Get desc # of RetFile$
- Call ReturnName ; Return the file name
- Sub Ax,Ax ; zero return code
- FindFirst02:
- Mov Bx,[Bp+6] ; Er% adr.
- Mov [Bx],Ax ; return erro code
- Pop Bp
- Ret
- FindFirst Endp
- ;
- ;
- ; Find next matching file name
- ; Stack Frame:
- ; Bp+8 Desc. No. of RetFile$
- ; Bp+6 Adr. of Er%
- ; Bp+4 Return Segment
- ; Bp+2 Return Offset
- ; Bp+0 Saved Bp
- FindNext Proc Far
- Push Bp
- Mov Bp,Sp
- Call SetDta ; Set DTA to our area
- Mov Ah,4fh
- Int 21h ; Search for next file
- Jc FindNext02 ; error
- Mov Ax,[Bp+8] ; Desc # of RetFile$
- Call ReturnName ; return the file name
- Sub Ax,Ax
- FindNext02:
- Mov Bx,[Bp+6]
- Mov [Bx],Ax ; save error code
- Pop Bp
- Ret
- FindNext Endp
- ;
- ;
- ;; Set DTA to our file structure
- SetDta:
- Push Ds
- Mov Ax,Cs
- Mov Ds,Ax
- Lea Dx,FileStruc
- Mov Ah,1ah
- Int 21h ; Set DTA
- Pop Ds
- Ret
- ;
- ;
- ;; Return the file name to string desc # in Ax
- ReturnName:
- Shl Ax,1
- Shl Ax,1 ; Mult by 4
- Mov Bx,Ax
- Mov Es,Ds:[6] ; Desc segment in Es
- Mov Cx,Es:[Bx] ; get current length in Cx
- Mov Es,Es:[Bx+2] ; put string's segment in Es
- Jcxz ReturnNameEnd ; string has no length
- Push Cx ; save length
- Mov Di,2 ; offset of string
- Cld
- Mov Al,' '
- Rep Stosb ; fill string with spaces
- Lea Si,FName ; Si=adr. of file name
- Mov Di,2 ; adr. to put file name
- Pop Cx ; restore string's original length
- ReturnName02:
- Mov Al,Cs:[Si]
- Inc Si
- Or Al,Al
- Jz ReturnNameEnd ; end of file name
- Stosb ; save character
- Loop ReturnName02 ; loop until end of name or out of space
- ReturnNameEnd:
- Ret
- ;
- ; Data goes here
- ;
- FileStruc label byte
- Reserved Db 21 dup (0) ; Reserved by DOS
- Atrib Db 0 ; Atribute of the file
- FTime Dw 0 ; Last time file was modified
- FDate Dw 0 ; Last date file was modified
- FSize Dd 0 ; Long word of file size
- FName Db 13 dup (0) ; Actual file name
- ;
- Cseg Ends
- End Start