locked
'DirectoryInfo' is a type in 'IO' and cannot be used as an expression RRS feed

  • Question

  • I continualy recieve this error no matter what i try please try help, I'm trying to display the the directory information for a give drive

    Example:

    C:\ NTFS  500 000 000 Bytes

    code:

    Private Sub BtnCheckDestination_Click(sender As System.Object, e As System.EventArgs) Handles BtnCheckDestination.Click
        Dim hdrive As Int64
        Dim di As New IO.DirectoryInfo("H:")
    
        di = IO.DirectoryInfo("H:\").ToString
    
        TxtDestination.Text = (di).ToString

    Thanks!

    Wednesday, March 12, 2014 11:37 AM

Answers

  • Hi,

     I you are trying to get info about a drive then you would use the DriveInfo class like this.

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim di As New IO.DriveInfo("C:\")
            Dim str As String = di.Name & "   " & di.DriveFormat & "   " & di.TotalSize & " Bytes"
            MessageBox.Show(str)
        End Sub
    

    • Marked as answer by Timothy Barnsley Wednesday, March 12, 2014 12:00 PM
    • Unmarked as answer by Timothy Barnsley Wednesday, March 12, 2014 12:01 PM
    • Proposed as answer by Rbie Wednesday, March 12, 2014 12:04 PM
    • Marked as answer by Carl Cai Thursday, March 20, 2014 5:18 AM
    Wednesday, March 12, 2014 11:48 AM
  • Just replace the messagebox line with

    textbox1.text =  str

    'textbox1 should ofc be the name of your textbox


    • Edited by Rbie Wednesday, March 12, 2014 12:06 PM
    • Marked as answer by Carl Cai Thursday, March 20, 2014 5:18 AM
    Wednesday, March 12, 2014 12:04 PM
  • I tried that but it says value of type 'String' cannot be converted to ' System.windows.Forms.TextBox'

      This will work if you assign the string to the textbox .Text property like this.

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim di As New IO.DriveInfo("C:\")
            Dim str As String = di.Name & "   " & di.DriveFormat & "   " & di.TotalSize & " Bytes"
            TextBox1.Text = str
        End Sub
    

    • Proposed as answer by Devon_Nullman Thursday, March 13, 2014 2:23 AM
    • Marked as answer by Carl Cai Thursday, March 20, 2014 5:18 AM
    Wednesday, March 12, 2014 4:43 PM

All replies

  • Hi,

     I you are trying to get info about a drive then you would use the DriveInfo class like this.

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim di As New IO.DriveInfo("C:\")
            Dim str As String = di.Name & "   " & di.DriveFormat & "   " & di.TotalSize & " Bytes"
            MessageBox.Show(str)
        End Sub
    

    • Marked as answer by Timothy Barnsley Wednesday, March 12, 2014 12:00 PM
    • Unmarked as answer by Timothy Barnsley Wednesday, March 12, 2014 12:01 PM
    • Proposed as answer by Rbie Wednesday, March 12, 2014 12:04 PM
    • Marked as answer by Carl Cai Thursday, March 20, 2014 5:18 AM
    Wednesday, March 12, 2014 11:48 AM
  • This is exactly what i'm looking for thank you so much mynonly other issue is i have a text box and i'd like for the results to be put on in the text box
    Wednesday, March 12, 2014 11:54 AM
  • Just replace the messagebox line with

    textbox1.text =  str

    'textbox1 should ofc be the name of your textbox


    • Edited by Rbie Wednesday, March 12, 2014 12:06 PM
    • Marked as answer by Carl Cai Thursday, March 20, 2014 5:18 AM
    Wednesday, March 12, 2014 12:04 PM
  • I tried that but it says value of type 'String' cannot be converted to ' System.windows.Forms.TextBox'
    Wednesday, March 12, 2014 12:22 PM
  • did you add the .text as in

    textbox1.text = str

    Wednesday, March 12, 2014 12:28 PM
  • I tried that but it says value of type 'String' cannot be converted to ' System.windows.Forms.TextBox'

      This will work if you assign the string to the textbox .Text property like this.

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim di As New IO.DriveInfo("C:\")
            Dim str As String = di.Name & "   " & di.DriveFormat & "   " & di.TotalSize & " Bytes"
            TextBox1.Text = str
        End Sub
    

    • Proposed as answer by Devon_Nullman Thursday, March 13, 2014 2:23 AM
    • Marked as answer by Carl Cai Thursday, March 20, 2014 5:18 AM
    Wednesday, March 12, 2014 4:43 PM