Results 1 to 13 of 13

Thread: File copy problem, need help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    Posts
    30

    Cool

    Well of all the help i got from this boared i have been able to finish a lot of things on the program i was making, but i have this problem that is the main part of the program. It is a file copy problem:
    Code:

    Private Sub backup_Click()
    Dim MyData As String
    Dim dData As String
    MyData = App.Path & "\Data\Bin"
    dData = App.Path & "\Data\Backup"

    FileCopy "MyData", "dData"

    Then someone said that you don't use quoted but then if you replace the filecopy without quotes it still doesnt work.

    FileCopy MyData, dData

    Then if you try to put parenthesese like in an example it wants a = sign.

    FileCopy(MyData, dData)
    But when you put in an equal sign
    FileCopy = MyData, dData
    It still gives an error, help!!
    As you can see i've tried many diffrent ways to try to get the line

    FileCopy "MyData", "dData" to work. But it just doesnt seem to, please help! Thanks!
    Dreys
    "Your worst enemy is your greatest teacher."

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    well, is the file your trying to copy already open? What was your original error?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Guest
    MyData = App.Path & "\Data\Bin"
    dData = App.Path & "\Data\Backup"

    Does Bin exist?
    Does Backup exist?
    Is it a folder or a file?

  4. #4
    Addicted Member darrenl's Avatar
    Join Date
    Jul 2000
    Location
    Portsmouth, UK
    Posts
    148
    I guess you are trying to copy multiple files, as you are not specifing a file name in your MyData and dData variables. Unfortunatly you are going to have to explicitly tell FileCopy what the file names of what you want to copy are.

    FileCopy App.Path & "\Data\Bin" & file1.dat", = App.Path & "\Data\Backup\File2.dat"
    FileCopy App.Path & "\Data\Bin" & file2.dat", = App.Path & "\Data\Backup\File2.dat"

    etc.

    Hope this helps.
    Dazzer

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    Posts
    30
    For the comments on does bit exist and does backup exist.
    Bin is the folder i want to be copied, backup is the folder i want to be created. So that way backup now has the bin files & or folder. I am trying to copy entire folders from one spot to another.
    Dreys
    "Your worst enemy is your greatest teacher."

  6. #6
    Guest
    FileCopy is not designed to move multiple files.

    Use the SHFileOperation api function to do this.

    Code:
    Public 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
      
    Public Const FO_MOVE = &H1
    Public Const FO_COPY = &H2
    Public Const FO_DELETE = &H3
    Public Const FO_RENAME = &H4
    
    Public Const FOF_SILENT = &H4
    Public Const FOF_RENAMEONCOLLISION = &H8
    Public Const FOF_NOCONFIRMATION = &H10
    Public Const FOF_SIMPLEPROGRESS = & H100 
    Public Const FOF_ALLOWUNDO = &H40
    
    
    Public Declare Function SHFileOperation _
        Lib "shell32.dll" Alias "SHFileOperationA" _
        (lpFileOp As SHFILEOPSTRUCT) As Long
    
    
    Private Sub Command1_Click()
    Dim SHF As SHFILEOPSTRUCT
    Dim lret As Long
    Dim MyData, dData As String
    
    MyData = App.Path & "\Data\Bin\*.*" 
    dData = App.Path & "\Data\Backup\" 
    
    SHF.wFunc = FO_COPY
    SHF.hWnd = Me.hWnd
    
    SHF.pFrom = MyData
    SHF.pTo = dData
    SHF.fFlags = FOF_SILENT
    
    lret = SHFileOperation(SHF)
    
    'Returns 0 if successful
    If lret <> 0 Then
        MsgBox "Error"
    End If
    
    End Sub

  7. #7
    Addicted Member darrenl's Avatar
    Join Date
    Jul 2000
    Location
    Portsmouth, UK
    Posts
    148
    in that case can i suggest you use the FileSystemObject, it has a copyfolder method that would suit you.

    Dim fs as object

    Set fs = CreateObject("Scripting.FileSystemObject")

    fs.createfolder (App.Path & "\Data\Backup\")

    fs.CopyFolder App.Path & "\Data\Bin\*", App.Path & "\Data\Backup\",true

    the last parameter tells the FSO to overwrite any duplicate files.

    Dazzer

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2000
    Location
    Posts
    30
    darrenl, i used the stuff you gave me and it gave me no errors, but then when i clicked the button it it gave me an error of Path not found. But the error was pointing to the line
    fs.CreateFolder (App.Path & "..\Dune2000\Data\Backup")
    Specifically. The path isnt found because its suppose to create it...
    Im not sure what exactly im suppose to do.
    Dreys
    "Your worst enemy is your greatest teacher."

  9. #9
    Guest
    For FSO:

    Code:
    Dim FSO as Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Dim MyData, dData As String
    
    MyData = App.Path & "\Data\Bin\" 
    dData = App.Path & "\Data\Backup\" 
    
    FSO.MoveFolder MyData, dData
    But the API function works as well.

  10. #10
    Addicted Member Jakys's Avatar
    Join Date
    Dec 1999
    Location
    Norway
    Posts
    180
    To create a folder just use the old ms-dos command mkdir!

    ex:
    MkDir "C:\test"

  11. #11
    Addicted Member darrenl's Avatar
    Join Date
    Jul 2000
    Location
    Portsmouth, UK
    Posts
    148
    Dreys, the line
    Code:
    fs.createfolder (App.Path & "\Data\Backup\")
    will create the destination folder before copying the files.


    The MoveFolder method that Mathew uses will move the data into your backup folder and not leave files behind. Whereas the copyfolder method will leave files behind. And if the folder destination folder exists an error will be generated, whereas the copyfolder method will overwrite.

    Enjoy.
    Dazzer

  12. #12
    Guest
    Originally posted by Jakys
    To create a folder just use the old ms-dos command mkdir!

    ex:
    MkDir "C:\test"
    Always check before making a folder to see if it exists already or you will get an error.

    Code:
    If Not Dir("C:\test", vbDirectory) = "" Then
         MkDir "C:\test"
    Else
         Exit Sub
    End If

  13. #13
    Addicted Member Jakys's Avatar
    Join Date
    Dec 1999
    Location
    Norway
    Posts
    180

    Talking

    Sorry, forgot that part. But you could also write

    on error resume next

    before the line where you expect an error. That would prevent an error message to appear (but of course it could be useful to know if the directory exists, then you could create a dir with another name)

    [Edited by Jakys on 11-23-2000 at 04:08 PM]

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