使用MoveFile方法在vbscript中覆盖Destination中的文件? [英] Issue with MoveFile method to overwrite file in Destination in vbscript?
问题描述
现在,我的主要命令是这样的:
$ $ $ $ $ $ $ c $ fso.MoveFile ObjFile.Path,archiveTo& \& yearValue& \& monthValue& \& ObjFile.Name
有没有一种方法可以将其默认为总是覆盖destionation目录中的文件已经存在?
不幸的是,VBScript MoveFile
目标文件不存在。它不能覆盖这样的文件存在,只是抛出错误。
所以唯一的选择是使用CopyFile(它有覆盖选项),然后DeleteFile:
p> fso.CopyFile ObjFile.Path,archiveTo& \& yearValue& \& monthValue& \& ObjFile.Name,True
fso.DeleteFile ObjFile.Path
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?
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
这篇关于使用MoveFile方法在vbscript中覆盖Destination中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!