0

I'm trying to difference when the user drops a folder or a file but i get a error.

UPDATE

The error is:

Conversion from string "C:\Users\Administrador\Desktop\W" to type 'Long' is not valid.

(Notice that the path, is incomplete)

The IDE highlights this error-line:

If ((attributes And FileAttributes.Directory) = FileAttributes.Directory) Then

I don't know if the problem is in the conversion or what, but if I use a msgbox before the problematic error-line, I can see how the path is correct:

MessageBox.Show(Objetos(0))
If ((attributes And FileAttributes.Directory) = FileAttributes.Directory) Then

enter image description here

This is the sub:

Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles foldertextbox.DragDrop
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        Dim Objetos As String() = e.Data.GetData(DataFormats.FileDrop)

        Dim attributes = Objetos(0)
        If ((attributes And FileAttributes.Directory) = FileAttributes.Directory) Then
            MsgBox("it's a dir")
        Else
            MsgBox("it's a file")
        End If

        foldertextbox.Text = Objetos(0)
        userSelectedFolderPath = Objetos(0)
        My.Settings.folderpath = Objetos(0)
        My.Settings.Save()
        playerargs = Nothing
        updatecheckboxes()
    End If
End Sub
j0k
  • 22,600
  • 28
  • 79
  • 90
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417

1 Answers1

3

Your attributes variable actually holds the file/dir name/path, if you want to test if its a directory, you can try:

System.IO.Directory.Exists(attributes)

Like this:

If System.IO.Directory.Exists(attributes) Then
    MsgBox("it's a dir")
ElseIf System.IO.File.Exists(attributes) Then
    MsgBox("it's a file")
End If

UPDATE

Check this answer, has better checking, maybe was what you were looking for: .NET How to check if path is a file and not a directory?

Dim isDir As Boolean = (System.IO.File.GetAttributes(path) And 
        System.IO.FileAttributes.Directory) = FileAttributes.Directory
Community
  • 1
  • 1
fableal
  • 1,577
  • 10
  • 24