Hi Can anybody explain, How to copy folder in VB6. All the files in that folder should be copied. Please help
Try this code, it needs a form and a button(Command1) -
Option Explicit Private Declare Function SHFileOperation _ Lib "shell32.dll" _ Alias "SHFileOperationA" _ (lpFileOp As SHFILEOPSTRUCT) As Long Private Type SHFILEOPSTRUCT hWnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAborted As Boolean hNameMaps As Long sProgress As String End Type Private Const FO_COPY = &H2 Private Sub Command1_Click() If CopyFolder("From", "To") Then MsgBox "Copied" Else MsgBox "Not copied" End If End Sub Private Function CopyFolder(ByVal sFrom As String, _ ByVal sTo As String) As Boolean Dim SHFileOp As SHFILEOPSTRUCT On Error GoTo CF_Err CopyFolder = False With SHFileOp .wFunc = FO_COPY .pFrom = sFrom .pTo = sTo End With SHFileOperation SHFileOp CopyFolder = True Exit Function CF_Err: MsgBox "Following error occurd while copying folder " & sFrom & vbCrLf & _ Err.Description, vbExclamation, "Error message" End Function
Private Sub cmdBackup_Click() call FCopy End Sub Public Sub FCopy() On Error GoTo err: 'myFile - Change if desired Dim myFile As New FileSystemObject Set myFile = Nothing myFile.CopyFile App.Path & "\MyFolderFrom", App.Path & "\MyfolderTO\", True 'App.Path - if the folder you would like to copy is in the same path as your app 'Change according to your app 'MyFolderFrom - Source, can be the path of the folder to be copied 'MyfolderTO - Destination, the path where the folder will be copied to 'True - Condition if it will overwrite a current folder (with the same name) 'can be False MsgBox "Folder Copy Success.", vbInformation, "Information" Exit Sub err: MsgBox err.Description, vbCritical End Sub
Nice and short ABE, obviously from your database backup app.;)
@Daniwaber, Abelingaw has been through a lot on file copy and replace functions. Follow his lead....:)
On line 20, my bad.
myFile.CopyFile App.Path & "\MyFolderFrom", App.Path & "\MyfolderTO\", True
Replace it to
myFile.CopyFolder App.Path & "\MyFolderFrom", App.Path & "\MyfolderTO\", True
Keeping successfully created progs kinda good thing to do :cool:
Keeping successfully created progs kinda good thing to do
Thats for sure.:)
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...
Hi. Im using vb 2010. I want to dynamically add textboxes to my form by clicking on a button. I've google searched and so far this code worked:
Private Sub btn_addline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addline.Click Dim txtB1 As New TextBox Dim i For i = ...