0
我应该在此前言说我对Vb Script非常陌生。我有一些C#的经验,感觉非常相似。我正在努力完成一项工作任务。邮编覆盖修复程序
此任务将查找某个位置并查找比特定日期早的所有文件。然后脚本会将所有这些文件压缩到zip文件月份的zip文件夹中。这项任务将每月运行一次。编写的原始脚本(阅读:从谷歌拼凑而成)在小样本上运行良好。但是,当应用于超过10K文件的文件夹时,它会在大约3000个文件后停止归档。
然后我决定让脚本每周运行一次以降低影响。理想的情况是每周运行一次,并将所有文件编译到一个名为该月份的zip文件中。因此,该脚本运行may的第一个星期一,并将100个文件放在“May”文件夹中。然后在第二个星期一该脚本再次运行并将所有文件放入同一个5月zip文件中。我有这个问题,它覆盖了当前文件。
这是我的代码。有什么建议么?
OriginalDir = "C:\Users\me\Desktop\Log_Test\Test"
DoZips(OriginalDir)
Function DoZips(Dir1)
'create empty zip file
a = Split(Dir1,"\",-1)
MyZip = Dir1 & "\" & MonthName(Month(Now)-1) & "_" & "archive" & ".zip" 'Naming of the zip file
CreateObject("Scripting.FileSystemObject") _
.CreateTextFile(MyZip, True) _
.Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
'zip content into zip file
on error resume next
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFS.GetFolder(Dir1)
For Each File In oFolder.Files
If Right(LCase(file.path),4) <> ".zip" Then
If File.DateLastModified < Date Then 'Change this number to set the age cutoff
With CreateObject("Shell.Application")
.NameSpace(MyZip).CopyHere File.path 'Copy the file to the zip folder
wScript.Sleep 4000 'Set wait time between archive and delete to ensure complete file archive
file.delete 'Delete the file after archive
End With
End If
End If
Next
CreateObject("WScript.Shell").Popup "All Files in " & myZip & " Successfully zipped", 5, "Compression"
set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjLog = objFSO.CreateTextFile("C:\Users\me\Desktop\Log_Test\log.txt")
objLog.WriteLine nCompressed & " of" & ubound(arFiles) + 1 &_
" Eligible files were compressed and zipped to location " & myZip & " on " & Date
End Function
所以这样的事情:如果不是objFSO.FolderExists(MyZip)然后...创建文件夹? – livemas
也许与objFSO.FileExists虽然,因为压缩文件是一个文件,而不是一个文件夹? – Dave
啊太棒了!那是我做错了。非常感谢!!! – livemas