0

I'm having some issues with this program I'm trying to make. It's a simple program that deletes a folder from my SD card. But when I go to run it, click the button that does this action, it spits out this error:

Could not find a part of the path 'C:\sdcafiine'.

This is the code I used:

Dim path As String = Form1.ComboBox1.Text & "\sdcafiine"
    System.IO.Directory.Delete(path, True)

I have another form that has a combobox in it with drive letters in it. This line of code basically reads the drive number and merges it with the path, to create something like "L:\sdcafiine", or "O:\sdcafiine."

For some reason, it replaces that read drive letter with "C:".

James Z
  • 12,209
  • 10
  • 24
  • 44
w60
  • 49
  • 7

1 Answers1

0

Nevermind, I got it to work.

It was in a BackgroundWorker, which may have not been a smart choice. I removed the BGWorker and put the code directly in the Button.Click method, and it works now.

w60
  • 49
  • 7
  • For future reference: You should _**NEVER**_ access the user interface directly from a background thread/task. If you need to interact with the UI from the background you must use `Control.Invoke()` in order to marshal the call to execute on the UI thread itself. For more information see: [How can I run code in a background thread and still access the UI?](https://stackoverflow.com/a/45571728/3740093) – Visual Vincent Nov 17 '18 at 08:12
  • The golden rule of WinForms is: _**Leave all UI related work on the UI thread!**_ – Visual Vincent Nov 17 '18 at 08:13