Removable Device Detection and File Copy

  • Thread starter Thread starter -OSD-
  • Start date Start date
O

-OSD-

Guest
Hi,

Trying to solve a very simple scenario where VB Forms applications should detect if the the attached disk /drive is the USB and if yes, copy some contents into this otherwise inform the user that no USB drive found.

Here is what I am doing, but seems like I have not desired results as "D" dive is fixed drive but application consider this as removable and never checks for the "E" drive.

Imports System.IO

Public Class Form1

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
For Each drive As IO.DriveInfo In My.Computer.FileSystem.Drives
If IO.Directory.Exists("D:\") And IO.DriveType.Removable Then
My.Computer.FileSystem.CopyFile("C:\Windows\Temp.txt", "D:\Temp.txt")
ElseIf IO.Directory.Exists("E:\") And IO.DriveType.Removable Then
My.Computer.FileSystem.CopyFile("C:\Windows\Temp.txt", "E:\Temp.txt")
Else
MessageBox.Show("No USB device found.")
End If
Next
End Sub
End Class

Continue reading...
 
Back
Top