[VB6] FileCopy help-VBForums
Results 1 to 5 of 5

Thread: [VB6] FileCopy help

  1. #1

    Thread Starter
    Fanatic Member neicedover1982's Avatar
    Join Date
    Jun 2005
    Abington, MA.

    [VB6] FileCopy help

    Hi, I copied this code right off of a website and I am still getting errors. I have 2 folders, each containing some files and other folders with files. I want to copy one entire directory and replace the other.

    The code I have is as follows.
    VB Code:
    1. Dim orig_path, new_path As String
    2.     orig_path = App.Path & "/Support_Files/Blank_Profile/*.*"
    3.     new_path = App.Path & "/Profile/Profile/*.*"
    4.     FileCopy orig_path, new_path
    5.     MsgBox ("done")

    I get an error on the FileCopy line. I am trying to copy files and other directorys, so the actual list from the Blank_Profile looks like so;
    I need to copy all the files as well as the folders ship_1 and the files inside. There are more files but this is just an example. I read you can copy the contents of a directory but none of the code I have works. Please help.
    Kevin | New England Iced Over | http://www.kevincawleyjr.com

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    @ Opera Software

    Re: [VB6] FileCopy help

    I moved your thread, since it actualy doesn't have anything to do with game or graphics programming...

    - ии -

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Center of it all

    Re: [VB6] FileCopy help

    If you use the XCOPY command from DOS, it will copy folders. You'd have to shell it.

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Tassie, Oz

    Re: [VB6] FileCopy help

    Try using the FileSystemObject, ie set a reference to Microsoft Scripting Runtime. I'm pretty sure it copies folders & files. eg
    VB Code:
    1. Dim fs As New FileSystemObject
    2.     Dim orig_path As String, new_path As String
    4.     orig_path = App.Path & "/Support_Files/Blank_Profile/*.*"
    5.     new_path = App.Path & "/Profile/Profile/"
    7.     fs.CopyFolder orig_path, new_path
    9.     Set fs = Nothing
    Note that you don't need the wildcards in the destination path.

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  5. #5
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Searching for mendhak

    Re: [VB6] FileCopy help

    VB Code:
    1. Private Type SHFILEOPSTRUCT
    2.     hWnd As Long
    3.     wFunc As Long
    4.     pFrom As String
    5.     pTo As String
    6.     fFlags As Integer
    7.     fAborted As Boolean
    8.     hNameMaps As Long
    9.     sProgress As String
    10. End Type
    12. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    14. Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.
    15. Const FOF_NOCONFIRMMKDIR = &H200 ' don't confirm making any needed dirs
    16. Const FO_COPY = &H2
    18. Private Function NuCopy(source As String, target As String) As Boolean
    19. 'Nucleus
    20. 'Copy file(s)/directories from source to destination
    21. 'In path of source either file(s) or folder and path of target as folder
    22. 'Out: Boolean indicating success
    23. If Right(source, 1) = "\" Then source = Left(source, Len(source) - 1)
    24. If Len(Dir$(target, vbDirectory)) <> 0 And (Len(Dir$(source, vbDirectory)) <> 0 Or Len(Dir$(target, vbDirectory)) <> 0) Then
    25.     Dim SHFileOp As SHFILEOPSTRUCT  ' structure to pass to the function
    26.     With SHFileOp
    27.         .wFunc = FO_COPY
    28.         .pFrom = source
    29.         .pTo = target
    31.     End With
    32.     NuCopy = (SHFileOperation(SHFileOp) = 0)
    33. End If
    34. End Function
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width