0
我有一个带有两个文本框的程序。一个是用于文件夹路径(目录)的另一个文件路径。现在,我的拖放功能正确地只允许一个文本框中的文件路径和另一个文件夹路径(目录)中的文件路径。在Visual Basic中拖放和验证(VS 2012 V11)
但是,我不确定我的验证方法是否正确。 这里是代码的两个部分验证,如果文件或目录:
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim filePathDragDrop() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
For Each pathTemp In filePathDragDrop
' This checks if it is a file
If File.GetAttributes(pathTemp) = FileAttributes.Archive Then
TextBoxCopyFrom.Text = pathTemp
End If
Next
End If
以及检查目录中的一个类似的设置,如上面只有这是不同
' Checks for directory
If File.GetAttributes(pathTemp) = FileAttributes.Directory Then
TextBoxCopyTo.Text = pathTemp
End If
这是正确的检查被删除的文件是否确实是一个文件, 以及被删除的文件夹(目录)确实是一个文件夹(目录)?
是否有任何可能被丢弃的项目会被错误验证?
我假设“FileAttributes.Archive”的归档部分属于文件数据。
好的,那有效!但是,有没有测试文件的东西是这样的:“如果(File.GetAttributes(pathTemp)和FileAttributes.Directory)= FileAttributes.File然后'它是一个文件'我知道没有”.file“但有东西测试文件(除了反向测试,“不是目录然后文件”)。 – user2348797 2013-05-08 23:16:16
这没有任何意义。 – 2013-05-08 23:31:20
我可能会假设:“If(File.GetAttributes(pathTemp)and FileAttributes.Directory)= FileAttributes.Directory”正在检查是否被拖放的项目是一个目录。如果“FileAttributes.Directory)= FileAttributes.Directory为true”,则被拖放的项目是一个目录。 “else”语句表示,如果被拖放的项目不是目录,则它必须是文件(例如:.txt,.exe,.oggs,.png,.jpg等)。我问的是,有没有办法查看拖放的内容是.txt,.ogg,.png等? – user2348797 2013-05-09 02:47:29