获取文件路径 文件复制
整么获取文件路径?点击button控件弹出选择路径的界面 还有整么把文件复制到选择的路径 整么在datagridview的同一列中添加文本和图片[此贴子已经被作者于2021-11-4 16:49编辑过]
程序代码:
'目录树中复制菜单
Private Sub treMenuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles treMenuCopy.Click
Dim sDir As String = ""
Dim sFileTo As String
If mySelectNode.Text.Length = 0 Then Return
sDir = Path.GetFullPath(mySelectNode.FullPath)
sFileTo = getCopyFile(sDir, "", True)
If sFileTo.Length = 0 Then Return
ShellCopyFile(Me.Handle, sDir, sFileTo)
End Sub
'获取复制文件的目标路径
Public Function getCopyFile(ByVal sDir As String, ByVal sFile As String, ByVal bOne As Boolean) As String
Dim fld As New FolderBrowserDialog
With fld
.RootFolder = Environment.SpecialFolder.Desktop
.SelectedPath = IO.Path.GetPathRoot(sDir)
If bOne Then
sFile = IIf(sFile.Length = 0, sFile, "\" & sFile)
.Description = "选择您想将 " & Chr(34) & Path.GetFullPath(sDir & sFile) & Chr(34) & " 复制到的地方,然后单击" & Chr(34) & "确定" & Chr(34) & "按钮"
Else
.Description = "选择您想将这 " & sFile & " 个项目复制到的地方,然后单击" & Chr(34) & "确定" & Chr(34) & "按钮"
End If
If .ShowDialog = DialogResult.OK Then
Return .SelectedPath
Else
Return ""
End If
End With
End Function
'调用API复制文件
'调用 ShellCopyFile(me.Handle, "c:\autoexec.bat", "d:\")
Public Function ShellCopyFile(ByVal hWnd As IntPtr, ByVal Source As String, ByVal Dest As String) As Integer
Dim fileOp As SHFILEOPSTRUCT = New SHFILEOPSTRUCT
Dim result As Integer
With fileOp
.hwnd = 0 ' hWnd
.wFunc = nFileMode.FO_COPY
.fAnyOperationsAborted = False
.pFrom = Source & vbNullChar
.pTo = IO.Path.GetFullPath(Dest) & vbNullChar & vbNullChar
.fFlags = nFileMode.FOF_ALLOWUNDO Or nFileMode.FOF_NOCONFIRMMKDIR
End With
result = SHFileOperation(fileOp)
'fAnyOperationsAborted = fileOp.fAnyOperationsAborted
Return result
End Function