基本代码:Ekkehard.Horner&由我改编 一世 发现 该 码, 谢谢大家。 Dim oShell,频率,sFile 昏暗goFS:设置goFS = CreateObject(“Scripting.FileSystemObject”) Dim oSrcDir:设置oSrcDir = goFS.GetFolder(“C:\ Temp1”) Dim sDstDir:sDstDir =“C:\ Temp2” Dim oFile,nInc,sNFSpec
Set oShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Temp1")
Set fc = f.Files
frequency = 10 * 1000
Const cnMax = 99
WScript.Sleep frequency
theDate = Year(Now()) _
& Right(String(2,"0") & month(Now()),2) _
& Right(String(2,"0") & Day(Now()),2)
For Each f1 in fc
If right(lcase(f1.name),4) = ".pdf" then
theBaseName = fso.GetBaseName(f1.name)
theExtension = fso.GetExtensionName(f1.Name)
f1.Move(fso.GetParentFolderName(f1.path) & "\" & theBaseName & "_" & EID & "_" & theDate & "." & theExtension)
End If
Next
For Each oFile In oSrcDir.Files
If right(lcase(oFile.name),4) = ".pdf" Then
nInc = 0
sNFSpec = getNewFSpec(oFile.Name, sDstDir, nInc)
Do While goFS.FileExists(sNFSpec) And nInc <= cnMax
sNFSpec = getNewFSpec(oFile.Name, sDstDir, nInc)
Loop
If nInc > cnMax Then
Else
oFile.Move sNFSpec
End If
End If
Next
Wend
}
Dim oShell, frequency, sFile
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim oSrcDir : Set oSrcDir = goFS.GetFolder("C:\Temp1")
Dim sDstDir : sDstDir = "C:\Temp2"
Dim oFile, nInc, sNFSpec
Set oShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\Temp1")
Set fc = f.Files
frequency = 10 * 1000
Const cnMax = 99
WScript.Sleep frequency
theDate = Year(Now()) _
& Right(String(2,"0") & month(Now()),2) _
& Right(String(2,"0") & Day(Now()),2)
For Each f1 in fc
If right(lcase(f1.name),4) = ".pdf" then
theBaseName = fso.GetBaseName(f1.name)
theExtension = fso.GetExtensionName(f1.Name)
f1.Move(fso.GetParentFolderName(f1.path) & "\" & theBaseName & "_" & EID & "_" & theDate & "." & theExtension)
End If
Next
For Each oFile In oSrcDir.Files
If right(lcase(oFile.name),4) = ".pdf" Then
nInc = 0
sNFSpec = getNewFSpec(oFile.Name, sDstDir, nInc)
Do While goFS.FileExists(sNFSpec) And nInc <= cnMax
sNFSpec = getNewFSpec(oFile.Name, sDstDir, nInc)
Loop
If nInc > cnMax Then
Else
oFile.Move sNFSpec
End If
End If
Next
Wend
}
答案 0 :(得分:1)
最简单的解决方案是从另一个本身“永远”(抽象)运行的脚本运行您的任务。
Dim oShell, frequency, sFile
Set oShell = CreateObject("WScript.Shell")
frequency = 10 * 1000 '10 Seconds (just for example)
sFile = "task.vbs" 'the script you want to run
While True 'make infinite cycle
WScript.Sleep frequency
oShell.Run sFile
Wend
答案 1 :(得分:0)
提议的解决方案Panayot Karabakalov也可以集成到现有脚本中:
'...
While True
For Each oFile In oSrcDir.Files
'...
Next
WScript.Sleep 30000 'milliseconds
Wend
'...
另一种变体是使用无条件Do ... Loop
代替While True ... Wend
:
'...
Do
For Each oFile In oSrcDir.Files
'...
Next
WScript.Sleep 30000 'milliseconds
Loop
'...