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,
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.
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
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.!!!
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.
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.