问题描述
我已经写了一个vbscript,用于将文件从源目录移动到目标目录。脚本目前的工作方式是,我有一个映射文件,读入(映射ID的文件夹类型)。每个被移动的文件都以id开头,目标将基于id映射到的内容。我读取映射文件并为每个正在移动的文件建立目标路径。这一切都按预期工作,问题是当我尝试移动目标目录中已存在的文件时,文件不会从源目录移动。基本上我想它覆盖目标目录中的文件,如果它已经存在。现在,我的主要命令是这样的:
$ $ $ $ $ $ $ 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中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!