Announcement

Collapse
No announcement yet.

Free Disk Space

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

  • Free Disk Space

    How do i determine the free disk space available?
    Can anyone give me an example?

    Thanks!!

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

  • #2
    See DISKFREE in help file?
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Thanks Mattias!!

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

      Comment


      • #4
        The PB DISKFREE command has the 2 or 4 GB limitation. Look into
        the GetDiskFreeSpaceEx() API function.


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

        Comment


        • #5
          Clay,

          Under 2k it report 82 gigs free on my machine.

          Russ

          ------------------
          "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers

          Comment


          • #6
            Code:
            'DiskSize.Bas  -- creates disksize.txt for reading by other programs
            ' Patrice Terriers' excellent code
            ' dvDiskFree - Returns the space left on very large hard disk.
            '
            ' This function works either with 95 OSR1    using GetDiskFreeSpace
            ' or 95 OSR2, 98 or NT 4.0 and NT 5.0        using GetDiskFreeSpaceEx
            '
            #COMPILE EXE
            #REGISTER NONE
            #INCLUDE "WIN32API.INC"
            DECLARE FUNCTION dvDiskFree&&(BYVAL DSK$)
            DECLARE FUNCTION dvDiskSize&&(BYVAL DSK$)
            
            FUNCTION PBMAIN AS LONG
               'ON ERROR GOTO PbMainError
               DIM DataBaseDir AS STRING, Answer$
               DataBaseDir$ = COMMAND$
               OPEN DataBaseDir$ + "DiskSize.Txt" FOR BINARY SHARED AS #1
               'IF ERR THEN MSGBOX "Error in open" + STR$(ERR)
               'PRINT #FileNum,FORMAT$(dvDiskSize&&(""),CHR$(44))  'total space on local drive
               'PRINT #FileNum,FORMAT$(dvDiskFree&&(""),CHR$(44))  'space left on local drive
               'PRINT #1,dvDiskSize&&("")  'total space
               'IF ERRCLEAR THEN MSGBOX "error 1" + STR$(ERR)
               Answer = SPACE$(16)
               'leave unformatted so any routine must convert on their end
               LSET Answer = FORMAT$(dvDiskFree&&(""))  'space left on local drive
            
               PUT #1,1,Answer$
               'IF ERRCLEAR THEN MSGBOX "error 2"
               'PRINT #1,dvDiskSize&&(DataBaseDir$)
               'IF ERRCLEAR THEN MSGBOX "error 3"
               'PRINT #1,dvDiskFree&&(DataBaseDir$)
               'IF ERRCLEAR THEN MSGBOX "error 4"
               FLUSH #1
               CLOSE #1
               MSGBOX answer
               'IF ERRCLEAR THEN MSGBOX "error 5"
            PbMainExit:
            EXIT FUNCTION
            PbMainError:
               MSGBOX "Error in PbMain (Disksize program) error #" & STR$(ERR)
               SLEEP 3000
               RESUME PbMainExit
            END FUNCTION
            
            FUNCTION dvDiskFree&&(BYVAL DSK$)            'Add EXPORT if DLL
                DIM Drive AS INTEGER
                DIM Done AS LONG
                DIM hLib AS LONG
            
                DIM pGetDiskFreeSpaceEx AS DWORD PTR
              ' Returns the number of free bytes on selected drive
                LOCAL d  AS ASCIIZ * 4
                LOCAL sc AS DWORD
                LOCAL bs AS DWORD
                LOCAL fc AS DWORD
                LOCAL tc AS DWORD
                Drive% = ASC(UCASE$(Dsk$))
                IF Drive% < 65 OR Drive% > 90 THEN Drive% = 0
                IF Drive% THEN
                   d = CHR$(Drive%) + ":\"
                ELSE
                   d = CURDIR$
                END IF
            
                Done& = 0
                hLib& = LoadLibrary("KERNEL32.DLL")
                IF hLib& THEN
                   pGetDiskFreeSpaceEx = GetProcAddress(hLib&, "GetDiskFreeSpaceExA")
                   IF pGetDiskFreeSpaceEx THEN
                      'changed CDECL to SDECL 
                      CALL DWORD pGetDiskFreeSpaceEx SDECL (d, lpFreeBytesAvailableToCaller&&, lpTotalNumberOfBytes&&, lpTotalNumberOfFreeBytes&&)
            
                      FUNCTION = lpFreeBytesAvailableToCaller&&
                      Done& = -1
                   END IF
                   CALL FreeLibrary(hLib&)
                END IF
                IF NOT Done& THEN
                   IF ISTRUE(GetDiskFreeSpace(d, sc, bs, fc, tc)) THEN
                      FUNCTION = CQUD(sc * bs * fc)
                   END IF
                END IF
            END FUNCTION
            
            '---------------------------------------------------------------------------
            ' dvDiskSize - Returns the size of very large hard disk.
            '
            ' This function works either with 95 OSR1    using GetDiskFreeSpace
            ' or 95 OSR2, 98 or NT 4.0 and NT 5.0        using GetDiskFreeSpaceEx
            '
            FUNCTION dvDiskSize&&(BYVAL DSK$)           'Add EXPORT if DLL
            ' This function works either with 95 OSR1    using GetDiskFreeSpace
            ' or 95 OSR2, 98 or NT 4.0 and NT 5.0        using GetDiskFreeSpaceEx
            
                DIM pGetDiskFreeSpaceEx AS DWORD PTR
            
              ' Returns the number of total bytes on selected drive
                LOCAL d  AS ASCIIZ * 4
                LOCAL sc AS DWORD
                LOCAL bs AS DWORD
                LOCAL fc AS DWORD
                LOCAL tc AS DWORD
                Drive% = ASC(UCASE$(Dsk$))
                IF Drive% < 65 OR Drive% > 90 THEN Drive% = 0
                IF Drive% THEN
                   d = CHR$(Drive%) + ":\"
                ELSE
                   d = CURDIR$
                END IF
                Done& = 0
                hLib& = LoadLibrary("KERNEL32.DLL")
                IF hLib& THEN
                   pGetDiskFreeSpaceEx = GetProcAddress(hLib&, "GetDiskFreeSpaceExA")
                   IF pGetDiskFreeSpaceEx THEN
                      'changed CDECL to SDECL
                      CALL DWORD pGetDiskFreeSpaceEx SDECL (d, lpFreeBytesAvailableToCaller&&, lpTotalNumberOfBytes&&, lpTotalNumberOfFreeBytes&&)
                      FUNCTION = lpTotalNumberOfBytes&&
                      Done& = -1
                   END IF
                   CALL FreeLibrary(hLib&)
                END IF
                IF NOT Done& THEN
                   IF ISTRUE(GetDiskFreeSpace(d, sc, bs, fc, tc)) THEN
                      FUNCTION = CQUD(sc * bs * tc)
                   END IF
                END IF
            END FUNCTION

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


            [This message has been edited by Mike Doty (edited December 04, 2004).]
            The world is full of apathy, but who cares?

            Comment


            • #7
              http://www.powerbasic.com/support/pb...ad.php?t=23262
              noticed lance's change to sdecl
              or search source code forum for diskfree

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


              [this message has been edited by mike doty (edited december 04, 2004).]
              The world is full of apathy, but who cares?

              Comment


              • #8
                Right you are, Russ! I just tried it on my XP machine, and it reported
                23GB. So, the IDE Help file is blatantly out in left field, as THAT
                is where I read that it has a 2GB limitation.


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

                Comment


                • #9
                  Sorry, folks. I'm afraid the PowerBASIC Help File is a little misleading.

                  Actually, as long as you're running anything other than the first release of Win95, PowerBASIC will measure DISKFREE and DISKSIZE accurately through the range of a 64-bit integer (a reasonably large number). With that first Win95, nothing will measure beyond 2G.

                  Regards,

                  Bob Zale
                  PowerBASIC Inc.


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

                  Comment


                  • #10
                    'DISKFREE/DISKSIZE won't report over 2,147,155,968 with Win98 SE.
                    'See CALL DWORD example in the PB help system
                    Code:
                    #DIM ALL      'DiskFree2 to overcome earlier Windows 95 not having GetDiskFreeSpaceExA
                                  'This is from CALL DWORD example in the docs
                    #INCLUDE "WIN32API.INC"
                    DECLARE FUNCTION MyDiskFreeSpaceEx _
                      (lpPath AS ASCIIZ, lpFreeToCaller AS QUAD, lpTotalBytes AS QUAD, lpTotalFreeBytes AS QUAD) AS LONG
                    
                    FUNCTION PBMAIN AS LONG
                      DIM result AS LONG, MyDrive AS STRING, MyDiskSize AS QUAD, MyDiskFree AS QUAD
                      MyDrive = "C:\"
                      
                      MyDiskSize = DISKFREE(MyDrive)
                      MSGBOX "Using Windows 98SE only get " & FORMAT$(MyDiskSize,"#,")   '2,147,155,968
                     
                      
                      CALL  Disksize2(MyDrive,MyDiskSize,MyDiskFree)
                      IF MyDiskSize > -1 THEN
                         MSGBOX "MyDiskSize: " + FORMAT$(MyDiskSize,"#,") & $CRLF & _
                        "MyDiskFree: " & FORMAT$(MyDiskFree,"#,")  & $CRLF & _
                        "Used space: " & FORMAT$(MyDiskSize-MyDiskFree,"#,")
                      ELSE
                         MSGBOX "Earlier version of Windows 95 can't use GetDiskFreeSpaceExA"
                      END IF
                    END FUNCTION
                    
                    SUB DiskSize2(Drive AS STRING,SizeOfDisk AS QUAD,TotalFree AS QUAD)
                      DIM hLib    AS DWORD
                      DIM pAddr   AS DWORD
                      DIM szDrv   AS ASCIIZ * %MAX_PATH
                      DIM lResult AS LONG
                    
                      szDrv = Drive
                    
                      DIM FreeToUserQuota AS QUAD
                      hLib = LoadLibrary("KERNEL32.DLL")
                      pAddr = GetProcAddress(hLib, "GetDiskFreeSpaceExA")
                      IF pAddr <> 0 THEN
                        CALL DWORD pAddr USING MyDiskFreeSpaceEx(szDrv, FreeToUserQuota&&, SizeOfDisk&&, TotalFree&&) TO lResult
                      ELSE
                        SizeOfDisk = -1
                        TotalFree  = -1
                      END IF
                    
                      FreeLibrary hLib
                    END SUB
                    ------------------




                    [This message has been edited by Mike Doty (edited December 10, 2004).]
                    The world is full of apathy, but who cares?

                    Comment

                    Working...
                    X