home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12334.ZIP / FCOUNT.ASM < prev    next >
Assembly Source File  |  1989-03-23  |  3KB  |  76 lines

  1. ; FCount.Asm - counts the number of files that match a specification
  2.  
  3. ;Syntax -
  4. ;
  5. ; Spec$ = "*.*" + CHR$(0)
  6. ; Count = FileCount%(Spec$)
  7. ; Where Spec$ holds the file specification, and Count is assigned the
  8. ; number of files that match.
  9.  
  10. .286
  11. .Model Medium, Basic
  12. .Code
  13.     Extrn DosFindFirst:Proc    ; Declare the OS/2 calls as external
  14.     Extrn DosFindNext: Proc
  15.     Extrn DosFindClose:Proc
  16.  
  17. FileCount Proc, Spec:Ptr
  18.  
  19.     Local Handle:      Word
  20.     Local Buffer [18]: Word   ;36 bytes
  21.     Local SearchCount: Word
  22.  
  23.     Xor  BX,BX            ;zero the count accumulator
  24.     Mov  SI,Spec          ;SI holds address of Spec$ descriptor
  25.     Mov  DX,[SI+02]       ;now DX points to the first character
  26.  
  27.     Mov  Handle, -1       ;directory handle of -1 to initiate search
  28.     Mov  SearchCount,1    ;number of entries to find
  29.  
  30.     Push DS               ;push segment of Spec$
  31.     Push DX               ;push offset of Spec$
  32.     Push SS               ;push segment of local Handle
  33.     Lea  AX,Handle        ;get Handle's address
  34.     Push AX               ;push it too
  35.     Push 00100111b        ;push attribute - all file types 
  36.                           ;(except directory)
  37.     Push SS               ;segment of buffer
  38.     Lea  AX,Buffer [18]   ;get address of buffer
  39.     Push AX               ;push it
  40.     Push 36               ;push length of buffer
  41.     Push SS               ;push segment of SearchCount
  42.     Lea  AX,SearchCount   ;get address of SearchCount
  43.     Push AX               ;push it
  44.     Push 0                ;push a DWord of 0's (Reserved& in 
  45.                           ;BASIC version)
  46.     Push 0
  47.     Call DosFindFirst     ;make call to find first occurrence of file
  48.     Or   AX,AX            ;was there a file by that name?
  49.     Jnz  Exit             ;if AX is not zero, then no file was found
  50.  
  51. Next_File:
  52.     Inc  BX               ;show that we got another matching file
  53.  
  54.     Push Handle           ;push handle
  55.     Push SS               ;push segment of buffer
  56.     Lea  AX,Buffer [18]   ;get address of buffer
  57.     Push AX               ;push it
  58.     Push 36               ;push length of buffer
  59.     Push SS               ;push segment of SearchCount
  60.     Lea  AX,SearchCount   ;get address of SearchCount
  61.     Push AX               ;push it
  62.     Call DosFindNext      ;make call to find first occurrence of file
  63.     Or   AX,AX            ;was there a file by that name?
  64.     Jz   Next_File        ;if not carry, keep looking
  65.  
  66. Done:
  67.     Push Handle           ;push handle
  68.     Call DosFindClose     ;close it
  69.  
  70. Exit:
  71.     Mov  AX,BX            ;assign the function output
  72.     Ret                   ;return to BASIC
  73.  
  74. FileCount Endp
  75. End
  76.