Sign in to follow this  
Followers 0
Alpinestar

Disk Space Problems

6 posts in this topic

Hi Guys

I'm attempting to write a program that checks the sizes of 2 files (database file and index file). It then multiples the total size by 3 ( to allow database growth), adds 600 mb for a new service installation and minuses this from the hard drive free space.

If the total is negative then a Insufficient space is displayed. My problem is that all the file sizes and in a different format so don't add up correctly.

I know that this could be v easy for someone, below is my code.

CODE
#include <GUIConstants.au3>

$Form1 = GUICreate("Disk Space", 410, 349, 193, 115)

$SimsMDF = FileGetSize("C:\Microsoft SQL Server 2005\MSSQL.1\Data\master.mdf")

$tSimsMDF = $SimsMDF /1048576

$lbMDF = GUICtrlCreateLabel("1st File Size", 16, 40, 109, 20)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

$lbLDF = GUICtrlCreateLabel("2nd File Size", 16, 71, 101, 20)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

$Label1 = GUICtrlCreateLabel("SQL Express Install", 12, 108, 124, 20)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

$Label2 = GUICtrlCreateLabel("Free Space C:\", 12, 140, 92, 20)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

$Label3 = GUICtrlCreateLabel("TOTAL", 10, 184, 44, 20)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

$Label4 = GUICtrlCreateLabel("VERDICT", 10, 245, 59, 20)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

$nFREESPACE = DriveSpaceFree("C:")

$tFREESPACE = $nFREESPACE /1048576

$inFREESPACE = GUICtrlCreateInput($nFREESPACE, 188, 139, 120, 20, $WS_BORDER)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

$Express = 600

$inEXPRESS = GUICtrlCreateInput($Express & " MB", 188, 104, 120, 20, $WS_BORDER)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

$SimsLDF = FileGetSize("C:\Microsoft SQL Server 2005\MSSQL.1\Data\master.ldf")

$tSimsLDF = $SimsLDF /1048576

$inLDF = GUICtrlCreateInput($tSimsLDF & " MB", 188, 75, 120, 20, $WS_BORDER)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

$inMDF = GUICtrlCreateInput($tSimsMDF & " MB", 188, 44, 120, 20, $WS_BORDER)

GUICtrlSetFont(-1, 10, 400, 0, "Arial")

GUISetState(@SW_SHOW)

$nTOTAL = $tSimsMDF + $tSimsLDF + $Express

$tSIMSTOTAL = ($tSimsLDF & $tSimsLDF /1048576)

$inTOTAL = GUICtrlCreateInput($nTOTAL, 188, 181, 120, 20)

GUICtrlSetFont(-1, 10, 800, 0, "Arial")

$tempcalculate = $tSIMSTOTAL *3

$tmpcalc = $tempcalculate + $Express

$calculate = $tmpcalc - $nFREESPACE

If $calculate < -1 Then

$inVerdict = GUICtrlCreateInput("Insufficient Space", 188, 242, 120, 20, $WS_BORDER)

ElseIf $calculate > -1 Then

$inVerdict = GUICtrlCreateInput("Sufficient Space", 188, 242, 120, 20, $WS_BORDER)

Else

$verdict = GUICtrlCreateLabel($calculate, 40, 136, 63, 28)

EndIf

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

Share this post


Link to post
Share on other sites



From the help file under FileGetSize():

Remarks

Does not work on directories.

Divide result by 1024 to get kilobyte equivalent, or divide by 1048576 to get megabyte equivalent.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

From the help file under FileGetSize():

:)

Thanks for the reply

My application is using only files and is dividing by 1048576. However I'm still getting strange result.

Share this post


Link to post
Share on other sites

Hi Guys

I'm attempting to write a program that checks the sizes of 2 files (database file and index file). It then multiples the total size by 3 ( to allow database growth), adds 600 mb for a new service installation and minuses this from the hard drive free space.

If the total is negative then a Insufficient space is displayed. My problem is that all the file sizes and in a different format so don't add up correctly.

I know that this could be v easy for someone, below is my code.

Here's a WMI query for the free space on a drive:

Dim $sComputer = "." 
Dim $sDisk = "C:" 

$oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sComputer & "\root\cimv2")
$colDisk = $oWMIService.ExecQuery ("Select * from Win32_LogicalDisk Where DeviceID = " & "'" & $sDisk & "'")

For $oDisk In $colDisk
$spacecalc = $oDisk.FreeSpace
MsgBox(0,"","Approximately " &($spacecalc/(1024*1024)) &" GB free on drive " &$sDisk)
Next

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

Thanks for the reply

My application is using only files and is dividing by 1048576. However I'm still getting strange result.

Too many math and logic errors to list. This performs the basis without the irrelevant GUI mess:

#include <GUIConstants.au3>

$SimsMDF = FileGetSize(@WindowsDir & "\explorer.exe")
$tSimsMDF = $SimsMDF / 1048576 ; Convert to MB

$nFREESPACE = DriveSpaceFree("C:") ; Already is in MB

$Express = 600

$nTOTAL = $tSimsMDF + $Express

; $tSIMSTOTAL = ($tSimsLDF & $tSimsLDF / 1048576) ; What is this for?!

$inTOTAL = GUICtrlCreateInput($nTOTAL, 188, 181, 120, 20)

$tempcalculate = $nTOTAL * 3
$tmpcalc = $tempcalculate + $Express
$calculate = $nFREESPACE - $tmpcalc

If $calculate < 0 Then
    MsgBox(16, "Insufficient Space", "Disk freespace = " & $nFREESPACE & @CRLF & _
            "Space required = " & $tmpcalc)
Else
    MsgBox(64, "Sufficient Space", "Disk freespace = " & $nFREESPACE & @CRLF & _
            "Space required = " & $tmpcalc)
EndIf

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

@PsaltyDS

Thanks for that, works a treat ! :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0