0

Im working on a program and I get this "Value of type '1-dimensional array of String' cannot be converted to 'String'."

heres the code that gets this error:

Label4.Text = System.IO.Directory.GetDirectories(Backup)

And heres the string

Dim Backup As String
        Backup = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.MineRbu"

3 Answers 3

2

The GetDirectories() method returns an array of strings. You're setting that to a string property (.Text).

Try this instead:

Dim dirs() As String = System.IO.Directory.GetDirectories(Backup)
Label4.Text = string.Join(vbCrLf, dirs)

This will extract all the directories into an array, then put each item onto your label (separated by a new line).

Sign up to request clarification or add additional context in comments.

Comments

1

The System.IO.Directory.GetDirectories(Backup) returns an array of strings.

You probably need to change it to this:

'This will insert each value returned from GetDirectories'
For Each Dir as String in System.IO.Directory.GetDirectories(Backup)
  Label4.text &= Dir & VbCrLF
Next

'Alternatively, if you just need the first result:'
Label4.text = System.IO.Directory.GetDirectories(0)

References

Comments

0

You should declare Backup as DirectoryInfo not of type string

Dim Backup As DirectoryInfo = New DirectoryInfo(path)

see Microsoft Example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.