我希望脚本将所有文件(所有文件扩展名*.*
)从INN文件夹移动到ERROR文件夹,时间超过5分钟。在我的示例中C:\CopyFlow\Directory test\Inn\
到C:\CopyFlow\Directory test\Inn\Error
所以我想了解如何移动文件以及如何查找比x-time 更早的文件。然而,把它放在一起对我来说是个问题。有谁知道我怎么能指出这个?
这是我到目前为止所得到的......
Dim age_threshold
age_threshold = 5
Dim folder_path
folder_path = WScript.Arguments(0)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.getFolder(folder_path)
Dim old_file_not_found
old_file_found = 0
For Each file in f.Files
Dim age
age = DateDiff("n", file.DateLastModified, Now)
If age > age_threshold Then
old_file_found = 1
.MoveFile "C:\CopyFlow\Directory test\Inn\*.*", "C:\CopyFlow\Directory test\Inn\Error"
Exit for
end if
Next
WScript.Quit
我以前是批处理的,所以这对我来说有点希望(来源http://www.evalesco.com/check-any-file-older-x-minutes-directory)。
现在我在这个脚本中设置(昏暗?)我的INN和ERROR文件夹?而且我非常确定if age
后跟.movefile
是错误的,所以我可能需要稍微纠正一下。
更新图片中缺少的是\error\
行错误(move.file
)后的反斜杠。
答案 0 :(得分:2)
如果没有提供该方法的对象,则无法调用方法,因此.MoveFile
应为fso.MoveFile
。但是,如果作为参数传递给脚本的文件夹中的任何文件超过5分钟,脚本将以当前形式从C:\CopyFlow\Directory test\Inn
移动所有文件。
您需要做的是将C:\test\inn
作为参数传递给脚本,并仅移动那些实际较旧的文件:
If age > age_threshold Then
file.Move "C:\test\inn\error\"
End If