Results 1 to 5 of 5

Thread: Getting c drive free space info?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    24

    Getting c drive free space info?

    HI guys..i'm having a problem...how do you get drive space info for c drive only?...the ones i found in the forums lists down all the drives..what i want to do is to display out the available disk space left on drive c on a message box or label..anyone knows how?

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: Getting c drive free space info?

    You need a reference to the Microsoft Scripting Runtime library. Select the Project menu's Add Reference command and click on the COM tab. Select the Microsoft Scripting Runtime entry and click OK.
    'assuming you have a textbox to input a drive and a button to get it's information
    Put this at the top of your class
    Imports Scripting

    for example if you want to get the free space of your c drive type in the textbox C:/ then press a button ok
    Code:
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            getinfodrive(TextBox1.Text)
        End Sub
    
        Sub getinfodrive(ByVal s As String)
            Dim drive As String
            Dim fso As New FileSystemObject()
            For Each drive In Directory.GetLogicalDrives
                If drive = s Then
                    Dim d As Drive = fso.GetDrive(drive)
                    MessageBox.Show(d.FreeSpace.ToString)
                    MessageBox.Show(d.TotalSize.ToString)
                End If
            Next
        End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    24

    Re: Getting c drive free space info?

    The size is shown in bytes?..is there a way to convert it to kb?

  4. #4
    Member Arto's Avatar
    Join Date
    Jul 2005
    Location
    Lappeenranta, Finland
    Posts
    41

    Re: Getting c drive free space info?

    1 kb is 1024 bytes. So it should be quite easy to calculate.
    "Testing? What's that? If it compiles, it is good, if it boots up, it is perfect."
    -Linus Torvalds

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    24

    Re: Getting c drive free space info?

    oh okay..thanks a lot..that solved it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width