Announcement

Collapse
No announcement yet.

File Size Without Opening File

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File Size Without Opening File

    Does Anyone know a DOS call or whatever that will return the size of a file without opening it? I don't want to LOF it because that requires opening the file which, under DOS I believe, changes the time/date stamp. I've looked at redirecting the DIR statement to a text file, but that's not very elegant. As a last ditch effort I could do the LOF, while saving and restoring the file time/date. But, again, I'd really like a simple function that just returns the time/date stamp without opening it? Thanks in advance,

  • #2
    Checkout the DOSUNIT.BAS file in your EXAMPLES directory... it contains a FileSize() function that uses the DOS DTA to obtain the size of a file.

    Lance
    PowerBASIC Support
    Lance
    mailto:[email protected]

    Comment


    • #3
      Opening a file does not change time/date stamp, until you write
      to it. However it's indeed more elegant (and faster) to get the
      filesize without opening each file. Besides, with the DOSUNIT
      method you can retrieve size, time stamp and attributes in the
      same manner, preserving DTA information (which, I found out, is
      very important when using a DIR$ loop)...

      Sebastian Groeneveld
      mailto:[email protected][email protected]</A>

      Comment


      • #4
        I'm interested in getting a snippet of that filesize() example or just
        some help with the same problem!

        my code:

        call gettime 'monitors time for display
        call cleanscrn 'clears parts of screen
        delay 0.1
        showerr$ = "Problem with Accounts.dat Under Label ScanG"
        on error goto founderr
        open datapath$+"accounts.dat" for input as #1
        do until eof(1)
        locate 8, 3, 0: print "Searching G:\INCOMING for New Files... "
        input #1, acc$
        call gettime
        call powerbar 'progress bar

        'here is where I need to know the size of the incoming file
        'so that I can be sure the transfer is complete before any further
        'manipulation???

        incoming$ = inpath$+"*."+acc$
        filename$ = dir$(incoming$)
        extension$ = right$(filename$, 3)
        if extension$ = acc$ then
        goto chkfound
        else
        goto skipfound
        end if

        The program is monitoring for incoming files (via modem) and
        while the file(s) is still transfering... I believe that the
        file size or byte size is (0) however, these are zip files and
        I can't open them or continue process until the transfer is
        complete.

        any help ?
        thank you in advance!

        ------------------
        /mjj

        Comment


        • #5
          I use this code for reading a file's size (and I've probably found it in DOSUNIT.BAS)
          Code:
          FUNCTION FileSize AS LONG
            DIM DtaSeg AS INTEGER, DtaOfs AS INTEGER
            GetDTA DtaSeg, DtaOfs
            DEF SEG = DtaSeg
               FUNCTION = PEEKL(DtaOfs+26)
            DEF SEG
          END FUNCTION
          
          SUB GetDTA(DtaSeg AS INTEGER, DtaOfs AS INTEGER)
            ! push DS
            ! mov  AX, &H2F00
            ! int  &H21
            ! lds  SI, DtaSeg
            ! mov  DS:[SI], ES
            ! lds  SI, DtaOfs
            ! mov  DS:[SI], BX
            ! pop  DS
          END SUB
          You can only call the function after you have used DIR$. So you might want to put it right after
          Code:
             incoming$ = inpath$+"*."+acc$
             filename$ = dir$(incoming$)
          Good luck

          ------------------
          Sebastian Groeneveld
          mailto:[email protected][email protected]</A>
          Sebastian Groeneveld
          mailto:[email protected][email protected]</A>

          Comment


          • #6
            Here is a way to get a file's size without opening it.
            FUNCTION FILE.SIZE&(BYVAL FILE.NAME$)PUBLIC
            W$=RTRIM$(FILE.NAME$)
            X$=DIR$(W$)
            P=REV.INSTR(1,W$,"\")
            IF P<>0 THEN W$=MID$(W$,P+1)
            IF UCASE$(X$)<>UCASE$(W$) THEN FILE.SIZE&=0:EXIT FUNCTION
            REG 1, &h2f00
            CALL INTERRUPT &h21
            DTASEG=REG(9)
            DTAOFF=REG(2)
            DEF SEG=DTASEG
            FILE.SIZE&=PEEKL(DTAOFF+26)
            DEF SEG
            END FUNCTION

            ------------------

            Comment


            • #7
              Mark.
              Your code is somewhat ummm, different. But if you are transmiting
              data via pretty much anything you need a protocol, in other words
              the sender and the receiver need to have an agreed method of data
              transfer.If you use something like Zmodem or Ftp etc. then
              file info is sent to your "client" before it receives the file.

              Comment


              • #8
                When I copy these routines into my program it does not like
                DEF SEG
                And says "Missing declaration: DEF"
                DEF SEG = DtaSeg

                Where am I going wrong?

                Ian

                ------------------
                Ian Docksey, TBS
                Ian Docksey, Trinitarian Bible Society

                Comment


                • #9
                  >Where am I going wrong?

                  You'd have to be using the wrong compiler to have the compiler "Not like" DEF SEG.

                  You <U>are</U> using the PowerBASIC for MS-DOS compiler, right?

                  MCM

                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    check my 2nd post in:
                    http://www.powerbasic.com/support/pb...ead.php?t=1328


                    ------------------
                    There are no atheists in a fox hole or the morning of a math test.
                    If my flag offends you, I'll help you pack.

                    Comment

                    Working...
                    X