Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with MoveFile method to overwrite file in Destination in vbscript?

I have a vbscript that I have written to move files from a source directory to a destination directory. The way the script works at the moment is that I have a mapping file which is read in (maps id's to folder type). Each file being moved begins with the id and the destination will be based on what the id is mapped to. I read in the mapping file and build up the destination path for each file being moved. This all works as expected, the problem is when I try to move a file that already exists in the destination directory, the files are not moved from the source directory. Essentially I would like it to overwrite a file in the destination directory if it already exists. At the moment, my main command is this:

fso.MoveFile ObjFile.Path, archiveTo & "\" & yearValue & "\" & monthValue & "\" & ObjFile.Name

Is there a way to default this to always overwrite a file in the destionation directory if it already exists?

like image 702
user1587060 Avatar asked Jun 12 '13 12:06

user1587060


1 Answers

Unfortunately, the VBScript MoveFile method works only when the target file does not exist. It can't overwrite such file when exists, just throw error.

So the only option is to use CopyFile (which does have option to overwrite) then DeleteFile:

fso.CopyFile ObjFile.Path, archiveTo & "\" & yearValue & "\" & monthValue & "\" & ObjFile.Name, True
fso.DeleteFile ObjFile.Path
like image 105
Shadow Wizard Hates Omicron Avatar answered Sep 20 '22 18:09

Shadow Wizard Hates Omicron