Pregunta

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!

¿Fue útil?

Solución

Here, you create an instance of DirectoryInfo:

Dim di As New IO.DirectoryInfo("H:")

Note that di is of type DirectoryInfo now.

In the next line, you try to use the type DirectoryInfo as an expression by using parenthesis (which won't work, that's what the compiler tells you) and you try to call ToString() on that:

di = IO.DirectoryInfo("H:\").ToString

You proprably want to call ToString() on the instance you just created. Also, you'll try to change the type of di to string, which will work if you set OPTION STRICT OFF, but it is generally not a good practice.


So you can just use:

Dim di = New IO.DirectoryInfo("H:\")
TxtDestination.Text = di.ToString()

Nonetheless, it seems you're looking for the DriveInfo class instead, e.g.:

Dim di = new DriveInfo(@"H:\");
TxtDestination.Text = String.Format("{0} {1} {2} Bytes", di.Name, di.DriveFormat, di.AvailableFreeSpace)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top