#2
apull2021-11-04 19:00
早前写了个文件浏览器玩的,相关代码供参考
程序代码: '目录树中复制菜单 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 只有本站会员才能查看附件,请 登录 |
[此贴子已经被作者于2021-11-4 16:49编辑过]