Move File needs to Overwrite also [VB6]-VBForums
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
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    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.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,996

    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
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    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.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.