VBScript检查文件夹中是否有文件以及是否有打印文件

时间:2014-04-12 20:28:04

标签: printing vbscript automation

我想要一个vbscript来检查文件夹中是否有文件以及是否有打印文件,等待一分钟然后将它们移动到另一个文件夹等待一分钟,然后从原始文件夹中删除它们再等一下并循环播放。如果文件夹中没有任何文件等待一分钟并循环播放。这就是我已经拥有的东西:

PrintFolder = "C:\Users\Bradley\Dropbox\PrintQueue\Pending" 
LogFolder = "C:\Users\Bradley\Dropbox\PrintQueue\Completed"
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim wshell
Set wshell = WScript.CreateObject("WScript.Shell")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(PrintFolder) 
Set colItems = objFolder.Items()
If objFSO.FileExists("PrintFolder\*") Then
 For Each colItems in colItems
         If colItems.Name <> WScript.ScriptName Then
                 colItems.InvokeVerb "&Print"
         End If
 Next
 WScript.Sleep 60000
 objFSO.MoveFile "PrintFolder\*", "LogFolder"
 WScript.Sleep 60000
 objFSO.DeleteFile("PrintFolder\*")
 WScript.Sleep 60000
 wshell.Run("eprint.vbs")
Else
 WScript.Sleep 60000
 wshell.Run("eprint.vbs")
End If 
编辑:对不起,我忘了说当我运行它时,即使PrintFolder中有文件也无法打印

3 个答案:

答案 0 :(得分:1)

PrintFolder = "C:\Users\Bradley\Dropbox\PrintQueue\Pending" 
LogFolder = "C:\Users\Bradley\Dropbox\PrintQueue\Completed"
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim wshell
Set wshell = WScript.CreateObject("WScript.Shell")
Set objShell = CreateObject("Shell.Application")

Do

Set objFolder = objShell.Namespace(PrintFolder) 
Set colItems = objFolder.Items()
If colitems.count > 0 Then
 For Each colItems in colItems
         If colItems.Name <> WScript.ScriptName Then
                 colItems.InvokeVerb "&Print"
         End If
 Next
 WScript.Sleep 60000
 objFSO.MoveFile "PrintFolder\*", "LogFolder"
 WScript.Sleep 60000
 objFSO.DeleteFile("PrintFolder\*")
End If 

WScript.Sleep 60000

Loop

答案 1 :(得分:0)

你应该问一个问题,而不是让我们猜你的问题。

If objFSO.FileExists("PrintFolder\*") Then

这里不允许使用通配符。相反,请计算一下colitems。

答案 2 :(得分:0)

这是我现在的工作脚本:

PrintFolder = "C:\Users\Bradley\Dropbox\PrintQueue\Pending" 
LogFolder = "C:\Users\Bradley\Dropbox\PrintQueue\Completed"
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim wshell
Set wshell = WScript.CreateObject("WScript.Shell")
Set objShell = CreateObject("Shell.Application")

Do

Set objFolder = objShell.Namespace(PrintFolder) 
Set colItems = objFolder.Items()
If colItems.Count > 0 Then
 For Each colItems in colItems
     colItems.InvokeVerbEx ("Print")
 Next
 WScript.Sleep 60000
 objFSO.MoveFile "C:\Users\Bradley\Dropbox\PrintQueue\Pending\*", "C:\Users\Bradley\Dropbox\PrintQueue\Completed"
 WScript.Sleep 60000
 objFSO.DeleteFile("C:\Users\Bradley\Dropbox\PrintQueue\Pending\*")
End If 

WScript.Sleep 60000

Loop
相关问题