0

基本代码:由 Ekkehard.Horner 编写并由我改编我找到了代码,谢谢大家。调暗 oShell、频率、sFile 调暗 goFS :设置 goFS = CreateObject("Scripting.FileSystemObject") 调暗 oSrcDir :设置 oSrcDir = goFS.GetFolder("C:\Temp1") 调暗 sDstDir :sDstDir = "C:\Temp2" 调暗 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

}
4

2 回答 2

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
于 2013-03-17T23:34:35.680 回答
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

'...
于 2013-03-18T18:04:36.717 回答