gabru Posted February 19, 2004 Posted February 19, 2004 i want to copy a folder inclusive all subfolders and all files to a specified location. How do i do that? I dont want to code this myself if there is a possibility to use an existing component. The best way for me would be to use the copy-dialog which the windows-explorer use because there is everything handled. all exceptions, etc. is there a way i can use this? thanks! Quote sometimes I blog... http://michal.grafix.at
Leaders dynamic_sysop Posted February 19, 2004 Leaders Posted February 19, 2004 if you want to move an entire directory without a loop , you can use the filesystemobject class. here's a quick example ... Dim tpFolder As Type = Type.GetTypeFromProgID("Scripting.FileSystemObject") Dim objFolder As Object = Activator.CreateInstance(tpFolder) Dim objArgs As Object() = {"C:\testing", "F:\testing", True} '/// C:\ existing path , F:\ path to copy to , overwrite if exists on F:\ already tpFolder.InvokeMember("CopyFolder", Reflection.BindingFlags.InvokeMethod, Nothing, objFolder, objArgs) objFolder = Nothing Quote
gabru Posted February 19, 2004 Author Posted February 19, 2004 thanks for it but i think its not the right solution for me because i need the explorers copy-dialog. i also want to execute the explorers copy-function ... so i think i need to use the windows api .. can anyone help? Quote sometimes I blog... http://michal.grafix.at
Leaders dynamic_sysop Posted February 19, 2004 Leaders Posted February 19, 2004 if you want to use the api way , here's a quick example i put together ( NOTE : if you want a silent copy , ie: NO progress dialog add FOF_SILENT for the fFlags of the structure ) ... Public Structure SHFILEOPSTRUCT Public hWnd As Integer Public wFunc As Integer Public pFrom As String Public pTo As String Public fFlags As Integer Public fAborted As Integer Public hNameMaps As Integer Public sProgress As String End Structure Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer Private Const FO_COPY As Int32 = &H2 Private Const FO_DELETE As Int32 = &H3 Private Const FO_MOVE As Int32 = &H1 Private Const FOF_SILENT As Int32 = &H4 '/// this will hide the progress box ( do NOT use if you wish to see progress ) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim shStructure As New SHFILEOPSTRUCT() Dim currentpath As String = "C:\testing" '/// folder to copy Dim newpath As String = "F:\testing" '/// new path With shStructure .wFunc = FO_COPY .pFrom = currentpath .pTo = newpath End With SHFileOperation(shStructure) End Sub Quote
gabru Posted February 19, 2004 Author Posted February 19, 2004 thanks thats what i needed. Quote sometimes I blog... http://michal.grafix.at
VBUser Posted March 20, 2004 Posted March 20, 2004 http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=4f9c27b0-c7f7-42ea-9bbe-83fe9bd50419 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.