How to use the shell function in vb6.0 to copy file from one directory to another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lavs
    New Member
    • Mar 2007
    • 16

    How to use the shell function in vb6.0 to copy file from one directory to another

    Halu! Is there anyone who could give me an advice about this code?
    I have a file named db1.mdb in with a full path of "c:\firstfolder \copy db1.mdb" which i want to transfer to another directory "e:\secondfolde r". This is supposed to be creating a backup routine for an application i am developing.
    This is the code that i used.

    I am using Visual Basic 6.0 Enterprise edition. My database was created in access. I am using a Windows XP Operating system.

    shell("cmd.exe /c " & "c:\firstfolder \copy db1.mdb e:\secondfolder ")
  • pureenhanoi
    New Member
    • Mar 2007
    • 175

    #2
    Originally posted by Lavs
    Halu! Is there anyone who could give me an advice about this code?
    I have a file named db1.mdb in with a full path of "c:\firstfolder \copy db1.mdb" which i want to transfer to another directory "e:\secondfolde r". This is supposed to be creating a backup routine for an application i am developing.
    This is the code that i used.

    I am using Visual Basic 6.0 Enterprise edition. My database was created in access. I am using a Windows XP Operating system.

    shell("cmd.exe /c " & "c:\firstfolder \copy db1.mdb e:\secondfolder ")
    i think you do not need using shell command. VB6 has procedure to copy file from source folder to destination folder. Try it:
    Code:
     
    On Error Resume Next
    filecopy "c:\firstfolder\db1.mdb","e:\secondfolder\db1.mdb"
    if Err then
           msgbox "copy error"
    end if

    Comment

    • Lavs
      New Member
      • Mar 2007
      • 16

      #3
      Originally posted by pureenhanoi
      i think you do not need using shell command. VB6 has procedure to copy file from source folder to destination folder. Try it:
      Code:
       
      On Error Resume Next
      filecopy "c:\firstfolder\db1.mdb","e:\secondfolder\db1.mdb"
      if Err then
             msgbox "copy error"
      end if

      Thank you very much... The code works... I had tried it before but i omitted the filetitle in the secondfolder that's why i got a path/file access error.

      Anyway it now works... thank you so much...

      By the way, if you have any idea about the other way i want, the one using shell to copy the file, please give me also. Because i want to be able to learn on supplying dos commands to shell function in vb6.0

      Comment

      • ansumansahu
        New Member
        • Mar 2007
        • 149

        #4
        Originally posted by pureenhanoi
        i think you do not need using shell command. VB6 has procedure to copy file from source folder to destination folder. Try it:
        Code:
         
        On Error Resume Next
        filecopy "c:\firstfolder\db1.mdb","e:\secondfolder\db1.mdb"
        if Err then
               msgbox "copy error"
        end if

        Yes you can use this command
        FileCopy "c:\firstfolder \db1.mdb","e:\s econdfolder\db1 .mdb"

        and this should copy the file from the sorce directory to the Target directory.

        thanks
        ansuman

        Comment

        • ansumansahu
          New Member
          • Mar 2007
          • 149

          #5
          Originally posted by Lavs
          Thank you very much... The code works... I had tried it before but i omitted the filetitle in the secondfolder that's why i got a path/file access error.

          Anyway it now works... thank you so much...

          By the way, if you have any idea about the other way i want, the one using shell to copy the file, please give me also. Because i want to be able to learn on supplying dos commands to shell function in vb6.0
          Hi ,

          Look at this link

          http://www.freevbcode. com/ShowCode.Asp?ID =499

          this will give you an idea on how to use Shell API for copying files.

          thanks
          ansuman sahu

          Comment

          • Lavs
            New Member
            • Mar 2007
            • 16

            #6
            Originally posted by ansumansahu
            Yes you can use this command
            FileCopy "c:\firstfolder \db1.mdb","e:\s econdfolder\db1 .mdb"

            and this should copy the file from the sorce directory to the Target directory.

            thanks
            ansuman

            Halu there! :-) thanks for sharing your ideas.

            I got the shell ( ) also...

            try this

            shell("cmd.exe /c " & "copy c:\firstfolder\ db1.mdb e:\secondfolder ")

            Comment

            Working...