VB.Net에서 많은 파일과 폴더를 동일한 디렉토리에 복사하는 앱을 만들고 있으며 Windows 탐색기를 사용하고 싶습니다 (사용자는 GUI를 사용하므로 오류 표시 나 파일 비교에 대해 걱정할 필요가 없습니다).
따라서 각 파일 / 폴더에 대해 이렇게하면 :
My.Computer.FileSystem.CopyDirectory(source_path, target_path, FileIO.UIOption.AllDialogs)
My.Computer.FileSystem.CopyFile(source_path, target_path, FileIO.UIOption.AllDialogs)
올바르게 작동하며 다음 창을 표시합니다.
하지만 파일 및 / 또는 폴더가 많고이를 반복하고 위의 명령을 호출하면 모두를 결합하는 단일 GUI를 실행하는 대신 각 파일 / 폴더에 대해 새 복사 창을 실행합니다. :
여러 파일 / 폴더 복사 프로세스를 단일 Windows 탐색기 복사 창 GUI로 결합 할 수 있습니까?
@Jimi 덕분에 나는의 방향을 지적 받았기 SHFileOperations
때문에 이것을하는 방법을 알아 냈습니다. 나는 이것을하기 위해 작은 수업을 만들었다.
Imports System.Runtime.InteropServices
Public Class NativeCopy
Private Enum FO_Func As Short
FO_COPY = &H2
FO_DELETE = &H3
FO_MOVE = &H1
FO_RENAME = &H4
End Enum
Private Structure SHFILEOPSTRUCT
Public hwnd As IntPtr
Public wFunc As FO_Func
<MarshalAs(UnmanagedType.LPWStr)>
Public pFrom As String
<MarshalAs(UnmanagedType.LPWStr)>
Public pTo As String
Public fFlags As UShort
Public fAnyOperationsAborted As Boolean
Public hNameMappings As IntPtr
<MarshalAs(UnmanagedType.LPWStr)>
Public lpszProgressTitle As String
End Structure
<DllImport("shell32.dll", CharSet:=CharSet.Unicode)>
Private Shared Function SHFileOperation(
<[In]> ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
End Function
Private Shared _ShFile As SHFILEOPSTRUCT
Public Shared Sub Copy(ByVal sSource As List(Of String), ByVal sTarget As String)
_ShFile.wFunc = FO_Func.FO_COPY
_ShFile.pFrom = String.Join(vbNullChar, sSource) + vbNullChar
_ShFile.pTo = sTarget
SHFileOperation(_ShFile)
End Sub
End Class
파일 및 / 또는 폴더를 복사하는 방법은 다음과 같습니다.
Dim copy_items_paths As List(Of String)
Dim target_path As String
NativeCopy.Copy(copy_items_paths, target_path)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다