Results 1 to 29 of 29

Thread: how to copy a file in vb6

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    39

    how to copy a file in vb6

    I need to make a program in vb6 that can make a copy of a file (any type of files) that i chose from the pc and save it to a diferent path.

    just a copy of the file to another place on the pc.

    regards
    Last edited by amd711; Apr 27th, 2009 at 10:42 AM.

  2. #2
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: how to copy a file in vb6

    From MSDN Library:

    FileCopy Statement Example
    This example uses the FileCopy statement to copy one file to another. For purposes of this example, assume that SRCFILE is a file containing some data.

    Dim SourceFile, DestinationFile
    SourceFile = "SRCFILE" ' Define source file name.
    DestinationFile = "DESTFILE" ' Define target file name.
    FileCopy SourceFile, DestinationFile ' Copy source to target.
    Example:

    FileCopy "C:\MyFile.txt", "C:\TestFiles\MyTestFile.txt"

  3. #3
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: how to copy a file in vb6

    using the api
    Declare Function LZCopy Lib "lz32.dll" Alias "LZCopy" (ByVal hfSource As Long, ByVal hfDest As Long) As Long
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    39

    Re: how to copy a file in vb6

    Thanks a lot RhinoBull
    but it didnt work, I have chosed the file to be copied and the distination and then i pressed copy. a message box "files done" appeared but no copy at that distination!!!!

  6. #6

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2009
    Posts
    39

    Re: how to copy a file in vb6

    well now its working
    thanks a lot
    the project is attached
    Attached Files Attached Files
    Last edited by amd711; Apr 27th, 2009 at 02:25 PM.

  8. #8

  9. #9
    New Member
    Join Date
    Aug 2013
    Posts
    7

    Re: how to copy a file in vb6

    I want to provide a backup option in my VB6 application, to copy the database to a pen drive. I tried the following code
    Dim sourcefile,Destinationfile as string
    Sourcefile=App.Path & "\HHA.mdb"
    Destinationfile="TxtDrive.text" & "\HHA.mdb"
    Filecopy Sourcefile,Destinationfile
    *****************
    It did not work."Permission denied" message is displayed.(App.Path->C:\My documents\HHA\HHA.mdb and destination->K:\HHA.mdb Please help me.

  10. #10
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    2,400

    Re: how to copy a file in vb6

    Nevermind that this is a 12 year old thread.....

    Are you sure the Folder "C:\My documents\HHA" exists?............

    and your variable "sourcefile" is not a string......
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,071

    Re: how to copy a file in vb6

    I'm not sure he knows the difference between a String literal and invoking a property of a control.

  12. #12
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    2,912

    Re: how to copy a file in vb6

    "Permission denied" errors usually means your source HHA.mdb is opened by an ADO/DAO connection already and cannot be accessed before all connections to it from ADO/DAO are closed.

    You cannot backup a "live" JET database that is currently in use or risk getting a corrupted copy of the data.

    cheers,
    </wqw>

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,071

    Re: how to copy a file in vb6

    Well if the posted code is real:

    Quote Originally Posted by mavtcr View Post
    Destinationfile="TxtDrive.text" & "\HHA.mdb"

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,419

    Re: how to copy a file in vb6

    Yep that is definitely an invalid path. Unless of course you have a folder in your current folder named txtDrive.txt To get what is in the text box remove the quotes surrounding TxtDrive.text

  15. #15
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    2,912

    Re: how to copy a file in vb6

    Quote Originally Posted by dilettante View Post
    Well if the posted code is real:
    Perhaps it's retyped in the text area of the forum with some obfuscation in mind because the original code contains confidental variable names and/or DB filenames. . .

    cheers,
    </wqw>

  16. #16
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,419

    Re: how to copy a file in vb6

    Looking again I see the error message shows what may be a valid path. In that case it could be running into permissions issues. Root folders are protected and may deny requests to copy files there. Try using a folder on the target drive as your target.

  17. #17
    New Member
    Join Date
    Aug 2013
    Posts
    7

    Re: how to copy a file in vb6

    I tried for testing by below code;
    Sourcefile="K:\HHA\Support\HHA.mdb"

    It worked well
    Again test by below code:

    Sourcefile="C:\My Documents\HHA\HHA.mdb"

    Again the same error message: Permission Denied

    ie. Copying from C: drive is not allowed.How can I overcome this . My application is in C:drive

    NB. I am very new to programming

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,071

    Re: how to copy a file in vb6

    There shouldn't be any "C:\My Documents" directory. At least not for a very long time (Win9x?).

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,071

    Re: how to copy a file in vb6

    Wasn't this "C:\Users\username\Documents" even as far back as NT 4.0? Or at least since Vista?

  20. #20
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    2,912

    Re: how to copy a file in vb6

    Try copying your HHA.mdb from C: with File Explorer.

    If you get permission denied again than you should try with something more powerful that feeble File Explorer.

    Do you use ADO or DAO to connect to this JET/mdb database?

  21. #21
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,071

    Re: how to copy a file in vb6

    Code:
    Option Explicit
    
    Private Sub Main()
        Const ssfPERSONAL = 5
    
        With CreateObject("Shell.Application")
            MsgBox .NameSpace(ssfPERSONAL).Self.Path & "\HHA\HHA.mdb"
        End With
    End Sub

  22. #22
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,419

    Re: how to copy a file in vb6

    Quote Originally Posted by dilettante View Post
    Wasn't this "C:\Users\username\Documents" even as far back as NT 4.0? Or at least since Vista?
    I think the \User folder was introduced with Vista. Nt, 2000 and XP used a folder named Documents and Settings and the my documents folder was a sub folder within.

    Of course there is no reason you could not create a folder off the root named My Documents.

  23. #23
    New Member
    Join Date
    Aug 2013
    Posts
    7

    Re: how to copy a file in vb6

    I use ADO to connect. I understand the problem is "Permission" To copy from C Drive . But how can I overcome it.Suppose I install the application in some other computer,most probably the application and the database file will be in C Drive.There also this error message will be displayed and the application will be collapsed. The what is a solution. Any idea?

    Once again Please mind, I am very new to programming, and have only little knowledge about computers.

  24. #24
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    2,912

    Re: how to copy a file in vb6

    Quote Originally Posted by mavtcr View Post
    I use ADO to connect. I understand the problem is "Permission" To copy from C Drive .
    If you put your database on D: drive you will get "permission denied" too. It doesn't matter if it's on C: drive or on D: drive. You will get "permission denied" if your database is on whatever drive. So this is not the root cause of your problem.

    You can prevent "permission denied" errors by closing every open ADO connection to your database. So to prevent read permission errors while copying your database file you have to first close every ADO connection that might lock portions of this database file so that FileCopy can succeed.

    cheers,
    </wqw>

  25. #25
    New Member
    Join Date
    Aug 2013
    Posts
    7

    Re: how to copy a file in vb6

    Dear WQWETO ,
    I have done it.Closed all database files before copying,But still the same result.Will you put the code for closing the ADO connection,If only I am wrong in my code.
    Thanks

  26. #26
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    2,912

    Re: how to copy a file in vb6

    Quote Originally Posted by mavtcr View Post
    Dear WQWETO ,
    I have done it.Closed all database files before copying,But still the same result.Will you put the code for closing the ADO connection,If only I am wrong in my code.
    Thanks
    Try copying the .mdb file *before* opening the first connection to the database by calling FileCopy immediately before your conn.Open statement just for testing purposes so to be sure there are no open ADODB connections oustanding when FileCopy fails.

    Closing all ADODB connections might not be that simple task depending on how you have your Data Access Layer structured. If you have server-side recordsets or ADODC controls littered across application forms this might even be mission impossible.

    cheers,
    </wqw>

  27. #27
    PowerPoster
    Join Date
    Feb 2006
    Posts
    22,071

    Re: how to copy a file in vb6

    Sounds like a pachinko machine program if there are multiple open connections on the same database. You would only need to do this in rare cases.

    The ADODC is a nightmare. It was only ever intended for very simple programs. Use its bigger brother instead: DataEnvironment.

  28. #28
    New Member
    Join Date
    Aug 2013
    Posts
    7

    Re: how to copy a file in vb6

    So it seems copying through programme is imposible. Then any other idea for copying the database file ,in case any thing happens to the computer of the user. Mind, it should be easy for a person who has little knowledge about computer.

  29. #29
    Addicted Member
    Join Date
    Mar 2007
    Posts
    172

    Re: how to copy a file in vb6

    Quote Originally Posted by Caskbill View Post
    From MSDN Library:



    Example:

    FileCopy "C:\MyFile.txt", "C:\TestFiles\MyTestFile.txt"
    Is there any way to use this with wildcards?

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