Results 1 to 6 of 6

Thread: Move File needs to Overwrite also [VB6]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Question Move File needs to Overwrite also [VB6]

    In my code I need to move a file from one folder to another, this is how I currently do it [and it works great except for...]

    Code:
    'Move Zip File to History Folder
    Name sLogPath As sHistoryPath + "\" + stodayLog
    So the only problem I have is if the file already exists I get an error, what I want is for it to overwrite (or delete the old copy then perform this option)
    So questions - should I use a different method (like what?) or should I delete the file if it exist before doing my Move? (how would I do that?)
    Thanks,

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Move File needs to Overwrite also [VB6]

    The copy you posted actually does a 'Rename' of the file, not a move.

    If you have an existing copy of a file, and you want to replace it with a new copy using standard VB, then you would have to delete the existing one first.

    However, I believe (someone else can verify this as I never use the FSO) that the File System Object has a method which will do both with one command.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Move File needs to Overwrite also [VB6]

    filecopy will copy over an existing file, without warning

    edit: the existing source file will still need to be deleted, for a move

    pete

  4. #4
    Addicted Member cha0s4u's Avatar
    Join Date
    Apr 2005
    Location
    new Delhi - 1ND1A
    Posts
    209

    Re: Move File needs to Overwrite also [VB6]

    Instead of using "MoveFile" thing use "CopyFile" - - because overwrite property works only with "CopyFile".

    and after copying the files u can always delete the original file.. to look like a move function!!!!

    FSO.CopyFile ( source, destination[, overwrite] )

    Argument -
    overwrite
    Optional. Boolean value that indicates if existing files are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. Note that CopyFile will fail if destination has the read-only attribute set, regardless of the value of overwrite.

    The last argument is what need to be taken care here by default its false thats y when u try to copy a file in dir already having a file by that name it gives u the err... so make its value as true and the move file will move files ,, overwriting files in the dir, having same name.!!!

  5. #5
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Move File needs to Overwrite also [VB6]

    Be aware that there is a difference between moving a file, and copying a file and deleting the original file.

    If you move a file, the security attributes are moved as well. If you copy a file, the new file will get the security attributes of the folder it is placed in.

    So if a user doesn't have permissions on the original file, but he has permissions on the target folder, he will be able to access the file if the file is copied, but he will not be able to access the file if the file is moved.

    Also copying a file takes longer then moving a file, if the source and destination is on the same drive.
    Frans

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Move File needs to Overwrite also [VB6]

    Quote Originally Posted by Frans C
    Be aware that there is a difference between moving a file, and copying a file and deleting the original file.

    If you move a file, the security attributes are moved as well. If you copy a file, the new file will get the security attributes of the folder it is placed in.

    So if a user doesn't have permissions on the original file, but he has permissions on the target folder, he will be able to access the file if the file is copied, but he will not be able to access the file if the file is moved.

    Also copying a file takes longer then moving a file, if the source and destination is on the same drive.
    This is an excellent, excellent point and one well worth bearing in mind.

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