Copying File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepkrn
    New Member
    • Apr 2007
    • 1

    Copying File

    How to copy file from one path to another path
  • SanjuMtr
    New Member
    • Mar 2007
    • 47

    #2
    Originally posted by sandeepkrn
    How to copy file from one path to another path
    ADD reference to your Project "Microsoft Scripting Runtime"
    Use FilesystemObjec t in Ur Project.
    Check The Different Property & method of filesystemobjec t.

    U will get u r Ans.Good Luck.

    1st U try find out the sol by yourself.if not possible I will give U the Solve in Details ok?

    Comment

    • cbbibleboy
      New Member
      • Apr 2007
      • 29

      #3
      Another simpler (and perhaps better) way of doing it is simply:

      Code:
      FileCopy "c:\a.txt", "c:\test\a.txt" // Copies file
      Kill "c:\a.txt" // Deletes original file
      This is the simplest way, but leaves out a lot of error-catching.

      Comment

      • SanjuMtr
        New Member
        • Mar 2007
        • 47

        #4
        Originally posted by cbbibleboy
        Another simpler (and perhaps better) way of doing it is simply:

        Code:
        FileCopy "c:\a.txt", "c:\test\a.txt" // Copies file
        Kill "c:\a.txt" // Deletes original file
        This is the simplest way, but leaves out a lot of error-catching.
        I think there r two Problems in this code.

        1)U can't say whether the File Exist in specific Path or not.
        if the file doesn't exist in specific Path then U will get a runtime error. for Both
        Statement.
        2)the requirement is to copy the file, not to move the file so the Kill statement is
        not required

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by SanjuMtr
          I think there r two Problems in this code.

          1)U can't say whether the File Exist in specific Path or not.
          if the file doesn't exist in specific Path then U will get a runtime error. for Both
          Statement.
          2)the requirement is to copy the file, not to move the file so the Kill statement is
          not required
          It is fairly simple to check whether the source/dest files exist before attempting the copy. It's well worth learning about FileSystemObjec t, as it provides much more functionality than the built-in commands. But it's not always necessary.

          Also, I think it was nice of cbbibleboy to throw in the extra code demonstrating how to zap the original file if required. However, it might have been nice to make a more prominent note about what/why, to avoid disasters.

          Oh, one other thing I'm curious about. What's the idea with the "//"? It doesn't compile under VB6. Is it...
          • from a different (probably later) version of VB?
          • from a different language, and shouldn't really be there?
          • intended to prevent accidental execution?
          • other?

          Comment

          • cbbibleboy
            New Member
            • Apr 2007
            • 29

            #6
            Yeah, that was just the simplest fix. And the '//' was an accident. I write in C most of the time so it was just a habit.

            Comment

            Working...