home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / disk_20.zip / FSIZE.ZIP / FSIZE.ASM next >
Assembly Source File  |  1986-06-21  |  7KB  |  172 lines

  1. comment /
  2. FSIZE.ASM --  get size of any file (or group of files that conforms to
  3.               a wildcard).  Requires dBASE III Plus or DR.  Disk space
  4.               occupied is returned in Bytes if less than 65536 (with
  5.               leading "B"), otherwise in Kbytes rounded DOWN! (no leading
  6.               letter).  Yes, it's true, I still haven't figured out how
  7.               to convert those doubleword sizes, that's why it comes back
  8.               in "K".  When I figure it out, I'll probably charge for it.
  9. syntax:
  10. load fsize
  11. memvar=spac(8)+"c:\mydir\*.*"    && will give space on drive c:, dir \mydir
  12. call fsize with memvar
  13.  
  14. returns:
  15. "E       c:\mydir\*.*"     && no files found or drive not ready  (ERROR)
  16. "B   999 c:\mydir\*.*"     && exactly 999 bytes in files
  17. "    999 c:\mydir\*.*"     && 999*1024 bytes in files
  18.                            && (at least, amount smaller than 1K disregarded)
  19.  
  20. I leave the breaking up of the string, testing for error, etc. to you.
  21.  
  22. *************************** WARNING ***************************
  23.  
  24. The fact that this stuff is free means something, namely that it's not
  25. ready for sale.  Experimental version!!!  All suggestions & complaints
  26. are welcome, but no guarantees are made!  If I take a suggestion from
  27. you and incorporate it, I will send you the updated code for free if &
  28. when I do update it (regardless of whether it is part of a for-sale type
  29. package).
  30. R. Russell Freeland (Synergy Corp.)
  31. voice: 305-792-1866
  32. Compuserve 76146,371
  33.  
  34. History:
  35. 6-4-1986  first version
  36. 6-21-1986 fixed so that (hopefully) it won't trash other data in dBASE's
  37.           memvar space
  38.  
  39.  
  40.  
  41. I used code from FIND.ASM to create this.
  42.  
  43.       Author:         Ross Nelson
  44.                       10 November 1983
  45.       Modified:       Tony Movshon
  46.                       8 August 1984
  47.  
  48. /
  49.  
  50.  
  51. CODESEG SEGMENT BYTE PUBLIC 'CODE'
  52.  
  53. FILESIZE  PROC FAR
  54.        ORG      0
  55.        ASSUME   CS:CODESEG,DS:codeseg
  56.  
  57.  
  58. BEGIN:
  59.        push     cs                      ;gotta use es as pointer to data,
  60.        pop      es                      ;otherwise trashes dBASE data
  61.        mov      byte ptr [bx],' '       ;not sure why, but garbage creeps in
  62.                                         ;otherwise for some reason
  63.        xor      bp,bp                   ;use BP for the low word accumulator
  64.        xor      si,si                   ;and si for the highword
  65.        call     find1st                 ;find first matching file
  66.        cmp      ax,0                    ;did we?
  67.        ja       next                    ;OK, add and find next
  68.        mov      byte ptr [bx],'E'       ;error
  69.        jmp      finish                  ;so return
  70. next:  ;if match is found
  71.        add      si,es:fsizeh            ;add to the accumlators
  72.        add      bp,es:fsizel
  73.        jnc      skip                    ;no carry, skip next statement
  74.        inc      si                      ;carry, add it to hiword
  75. skip:
  76.        call findnext                    ;find next match
  77.        cmp      ax,0                    ;see if we did
  78.        jne      next                    ;yeah, try again
  79.  
  80.        mov      dx,si                   ;now move accumulators to where
  81.        mov      ax,bp                   ;it's easier to work with them
  82. checksize:
  83.         cmp     dx,0                    ;is the highword empty?
  84.         jg      Kbytes                  ;calculate in Kbytes, it's big enough
  85.         mov     byte ptr [bx],'B'       ;signify bytes inst. of Kbytes
  86.         jmp     Bytes
  87.  
  88. Kbytes:
  89.         mov     si,1024d                ;let's get it in "K"
  90.         div     si
  91.         xor     dx,dx                   ;clear the remainder
  92.  
  93. Bytes:
  94.         ;-----------now convert number to an ASCII string
  95.         mov     cx,bx
  96.         add     bx,7                    ;we'll do it backwards
  97.         mov     si,10                   ;prepare to divide by 10
  98.         inc     cx
  99. nexdgt: div     si                      ;divide dx:ax by si
  100.         or      dx,30H                  ;convert remainder to ASCII digit
  101.         dec     bx                      ;backup in string
  102.         mov     [bx],dl                 ;store character
  103.         xor     dx,dx                   ;clear remainder
  104.         or      ax,ax                   ;all done?
  105.         jnz     nexdgt                  ;do next digit
  106. spaces:
  107.         cmp     cx,bx                   ;digits left?
  108.         je      finish                  ;no, finished
  109.         dec     bx                      ;backup
  110.         mov     byte ptr [bx],' '       ;put in a space
  111.         jmp     spaces                  ;check again
  112. finish:
  113.  
  114.  
  115. RET
  116. ;--------------data goes here, hopefully out of dBASE's way
  117.  
  118. dta:
  119. reserved   db  21 dup (?)
  120. attribute  db  ?
  121. time       dw  0
  122. date       dw  0
  123. fsizel     dw  0                        ;loword of the file size
  124. fsizeh     dw  0                        ;hiword
  125. name_ext   db  13 dup(?)
  126.  
  127. FILESIZE  ENDP
  128.  
  129. FIND1ST         PROC    NEAR
  130.  
  131.         mov     dx, offset es:DTA       ;point to info block
  132.         push    ds                      ;setup ds as cs to point to our data
  133.         push    cs
  134.         pop     ds
  135.         mov     ah, 1Ah                 ;request new DTA
  136.         int     21h                     ;from MSDOS
  137.         pop     ds                      ;get back dBASE ds
  138.         mov     dx,bx                   ;filename to find
  139.         add     dx,8                    ;where the filespec is
  140.         mov     cx,39                   ;with these attributes
  141.         mov     ah, 4Eh                 ;request search
  142.         int     21h                     ;of DOS
  143.         mov     ax,0                    ;assume failure
  144.         jc      DONE                    ;if CY, no match
  145.         inc     ax                      ;else success
  146. DONE:
  147.                 ret
  148. FIND1ST         ENDP
  149.  
  150. FINDNEXT        PROC    NEAR
  151.  
  152.         mov     dx, offset es:dta       ;point to info block
  153.         push    ds                      ;setup ds as cs to point to our data
  154.         push    cs
  155.         pop     ds
  156.         mov     ah, 1Ah                 ;request new DTA
  157.         int     21h                     ;from MSDOS
  158.         mov     ah, 4Fh                 ;request search
  159.         int     21h                     ;of DOS
  160.         pop     ds                      ;get back dBASE ds
  161.         mov     ax, 0                   ;assume 0 (failure)
  162.         jc      QUIT                    ;if CY, no match
  163.         inc     ax                      ;else TRUE (success)
  164. QUIT:
  165.                 ret
  166.  
  167. FINDNEXT        ENDP
  168.  
  169. CODESEG ENDS
  170.         END
  171.  
  172.