监视新文件的文件夹,打印它们,然后使用VB脚本将它们移动到另一个文件夹 [英] Monitor a folder for new files, print them and then move them to a different folder using VB Script

查看:82
本文介绍了监视新文件的文件夹,打印它们,然后使用VB脚本将它们移动到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是vbscript的新手,我正在构建一个脚本来完成以下操作。


1。监视要创建的新文件的文件夹。


2。打印这些文件


3。将文件移动到另一个文件夹。



虽然这看起来很简单,但我在时间上遇到了麻烦。 此文件夹将包含的所有文件都是pdf文件,范围从1页到60页。 我有一个有效的代码,但在遇到第一个pdf文件
后,打开进入该文件夹的pdf需要很长时间。这意味着它在脚本移动到新文件夹之前没有足够的时间打开。 有没有关于如何解决它的建议。 我应该提一下,这个文件夹
每分钟可以收到几个文件。 这将位于我们的传真服务器上。


strComputer ="。"

设置objWMIService = GetObject(" winmgmts:" _

   &安培;" {impersonationLevel =冒充} \\"!&安培; _

         strComputer的&安培;" \root\cimv2")

将colMonitoredEvents = objWMIService.ExecNotificationQuery _

    (" SELECT * FROM __InstanceCreationEvent WITHIN 20 WHERE" _

       &" Targetinstance Isa'CIM_DirectoryContainsFile'和"_

           &安培;" TargetInstance.GroupComponent = QUOT; _

 &NBSP ;             &安培;"'Win32_Directory.Name = QUOT;" C:\\\\测试文件夹"""")

执行
设置objLatestEvent = colMonitoredEvents.NextEvent


'打印新文件


TargetFolder =" C:\ test folder" 

 

 设置objShell = CreateObject(" Shell.Application")

 设置objFolder = objShell.Namespace(TargetFolder ) 

 设置colItems = objFolder.Items

 对于i = 0到colItems.Count - 1

      colItems.Item(i).InvokeVerbEx(" Print")

   Next


'关闭AcroRd32 .exe 


  strComputer ="。"

设置objWMIService = GetObject(" winmgmts:" _

&" {impersonationLevel = impersonate}!\\"& strComputer&" \root \ cimv2")

设置colProcessList = objWMIService.ExecQuery _

(" Select * from Win32_Process Where Name ='AcroRd32.exe'")

For colProcessList中的每个objProcess

objProcess.Terminate()

下一页


'在移动文件之前暂停 


设置WshShell = WScript。 CreateObject(" WScript.Shell")

  wscript.sleep 10000

 

'打印后移动文件


 

设置fso = CreateObject(" Scripting.FileSystemObject")

 设置fldr = fso.getFolder(" C :\ test文件夹")

 如果fldr.files.Count> 0然后是
  fso.MoveFile" C:\ test folder \ *"," C:\Documents and Settings \ddavis \Desktop \ testCompleted"


 


  End If




Loop



解决方案


I我是vbscript的新手,我正在构建一个脚本来完成以下操作。


1。监视要创建的新文件的文件夹。


2。打印这些文件


3。将文件移动到另一个文件夹。




你应该颠倒你的行动顺序:


  1. 监控一个文件夹,查找要创建的新文件。
  2. 将文件移动到另一个文件夹。
  3. 打印已设置存档属性的文件。
  4. 打印后重置​​存档属性。


I am new to vbscript, and I am building a script to complete the following actions.

1. Monitor a folder for new files to be created.

2. Print those files

3. Move the files to anothe folder .

Although this seems fairly simple, I am having trouble with the timing.  All of the files that this folder will contain are pdf files that can range from 1 page up to 60 pages.  I have a code that works but after it encounters the first pdf file it takes too long to open pdf that goes into the folder. Which means that it does not open in enough time before the script moves it to the new folder.  Are there any suggestions out there as to how to fix it.  I should mention that this folder could recieve several documents per minute.  This will be located on our fax server.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceCreationEvent WITHIN 20 WHERE " _
        & "Targetinstance Isa 'CIM_DirectoryContainsFile' and " _
            & "TargetInstance.GroupComponent= " _
                & "'Win32_Directory.Name=""C:\\\\test folder""'")
Do
Set objLatestEvent = colMonitoredEvents.NextEvent

'print the new files

TargetFolder = "C:\test folder" 
 
 Set objShell = CreateObject("Shell.Application")
 Set objFolder = objShell.Namespace(TargetFolder) 
 Set colItems = objFolder.Items
 For i = 0 to colItems.Count - 1
     colItems.Item(i).InvokeVerbEx("Print")
  Next

'close the AcroRd32.exe 

 strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'AcroRd32.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next

'pause before moving the files 

Set WshShell = WScript.CreateObject("WScript.Shell")
 wscript.sleep 10000
 
'Move the files after printing

 
Set fso=CreateObject("Scripting.FileSystemObject")
 Set fldr = fso.getFolder("C:\test folder")
 If fldr.files.Count > 0 then
 fso.MoveFile "C:\test folder\*", "C:\Documents and Settings\ddavis\Desktop\testCompleted"

 

 End If


Loop

解决方案

I am new to vbscript, and I am building a script to complete the following actions.

1. Monitor a folder for new files to be created.

2. Print those files

3. Move the files to anothe folder .

You should reverse the order of your actions:

  1. Monitor a folder for new files to be created.
  2. Move the files to another folder .
  3. Print the files that have the archive attribute set.
  4. Reset the archive attribute after printing.


这篇关于监视新文件的文件夹,打印它们,然后使用VB脚本将它们移动到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆