home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bm_rm.zip / FINDFILE.ASM < prev    next >
Assembly Source File  |  1989-08-02  |  3KB  |  98 lines

  1. ;findfile() - Find the first (or next) file matching a given specification.
  2. ;
  3. ;Syntax: int findfile (char *fspec, int attr, struct DTA *dta);
  4. ;
  5. ;fspec = ASCIIZ pathname, optionally including wildcard characters (find first)
  6. ;        or NULL pointer (find next)
  7. ;
  8. ;attr  = file attribute byte to use in the search
  9. ;
  10. ;dta   = pointer to a DTA structure to be filled in with directory information
  11. ;        for the next file which matches the pathname 
  12. ;
  13. ;Return value: Zero for success, or a DOS error code if no matching files found.
  14. ;
  15. ;Copyright (C) 1989 Brian B. McGuinness
  16. ;                   15 Kevin Road
  17. ;                   Scotch Plains, NJ 07076
  18. ;
  19. ;This function is free software; you can redistribute it and/or modify it under 
  20. ;the terms of the GNU General Public License as published by the Free Software 
  21. ;Foundation; either version 1, or (at your option) any later version.
  22. ;
  23. ;This function is distributed in the hope that it will be useful, but WITHOUT 
  24. ;ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  25. ;FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  26. ;details.
  27. ;
  28. ;You should have received a copy of the GNU General Public License along with 
  29. ;this function; if not, write to the Free Software Foundation, Inc., 675 Mass 
  30. ;Ave, Cambridge, MA 02139, USA.
  31. ;
  32. ;Version 1.0          July, 1989          MASM 5.1
  33.  
  34.         DOSSEG
  35.         .MODEL small,C
  36.         .DATA
  37.  
  38. olddta  dw 2 dup (?)    ;Location of old DTA.
  39.         .CODE
  40.  
  41. findfile proc uses bx cx dx ds es, fspec:ptr, attr:word, dta:ptr
  42.  
  43.         mov ax,@data
  44.         mov ds,ax
  45.  
  46.         mov ah,2FH              ;Save the location of the existing DTA.
  47.         int 21H
  48.         mov olddta[2],es
  49.         mov olddta,bx
  50.  
  51. ;Get pointer to the DTA structure to be filled in.
  52.  
  53. if @DataSize                    ;Far pointer
  54.         lds dx,dta
  55. else                            ;Near pointer
  56.         mov dx,dta
  57. endif
  58.         mov ah,1AH              ;Set up new DTA for file search.
  59.         int 21H
  60.  
  61.         mov cx,attr             ;Get the search attribute in CX.
  62.  
  63. ;Get pointer to file specification, if any.
  64.  
  65. if @DataSize                    ;Far pointer
  66.         cmp fspec, word ptr 0   ;For null pointer, find next match, if any.
  67.         jnz @F
  68.         cmp fspec[2], word ptr 0
  69.         jz getnext
  70. @@:     lds dx,fspec
  71. else                            ;Near pointer
  72.         cmp fspec, word ptr 0   ;For null pointer, find next match, if any.
  73.         jz getnext
  74.         mov dx,fspec
  75. endif
  76.  
  77.         mov ah,4EH              ;Search for first matching file.
  78.         int 21H
  79.         jmp short @F
  80.  
  81. getnext:mov ah,4FH              ;Search for next matching file.
  82.         int 21H
  83.  
  84. @@:     pushf
  85.  
  86.         lds dx,dword ptr olddta ;Restore the old DTA.
  87.         mov ah,1AH
  88.         int 21H
  89.  
  90.         popf
  91.         jc exit                 ;If we didn't find it, return error code.
  92.  
  93.         xor ax,ax               ;We found a file: return zero.
  94. exit:
  95.         ret
  96. findfile endp
  97.         end
  98.