Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用批处理文件监视文件夹的上次修改时间_Batch File_Alert_Monitor_Dos_Last Modified - Fatal编程技术网

Batch file 使用批处理文件监视文件夹的上次修改时间

Batch file 使用批处理文件监视文件夹的上次修改时间,batch-file,alert,monitor,dos,last-modified,Batch File,Alert,Monitor,Dos,Last Modified,我的工作站上有一个文件夹,每分钟都会添加文件。 我必须时不时地监视这个文件夹,以查看是否添加了新文件。 如果这个文件夹中没有新文件,比如说5分钟,我们将执行一个操作 我们是否可以将批处理文件用于此目的,如果在过去5分钟内没有添加新文件,窗口屏幕上会出现警报/弹出窗口。 另外,我是批处理新手。请让我知道这些步骤。纯粹使用批处理文件似乎不太可能完成您想要完成的任务 但是,您可以在一个相对简单/小的VB脚本中完成这项工作,不需要在系统上进行任何额外安装 '-----------------------

我的工作站上有一个文件夹,每分钟都会添加文件。 我必须时不时地监视这个文件夹,以查看是否添加了新文件。 如果这个文件夹中没有新文件,比如说5分钟,我们将执行一个操作

我们是否可以将批处理文件用于此目的,如果在过去5分钟内没有添加新文件,窗口屏幕上会出现警报/弹出窗口。
另外,我是批处理新手。请让我知道这些步骤。

纯粹使用批处理文件似乎不太可能完成您想要完成的任务

但是,您可以在一个相对简单/小的VB脚本中完成这项工作,不需要在系统上进行任何额外安装

'-------------------------------------------------------------
' Monitors a folder for new files and warns if they 
' are not being created within a certain time period.
'-------------------------------------------------------------
Dim intMinutes:      intMinutes = 5            ' minute threshold for warning of no new files
Dim strDrive:        strDrive = "c:"           ' drive to monitor
Dim strPath:         strPath = "\\temp\\"      ' path to monitor. remember to double slashes

Dim intTimer:        intTimer = "2"
Dim strComputer:     strComputer = "."
Dim objWMIService:   Set objWMIService = GetObject( "winmgmts:" &  "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2" )
Dim strQuery:        strQuery = "Select * From __InstanceOperationEvent" & " Within " & intTimer & " Where Targetinstance Isa 'CIM_DataFile'" & " And TargetInstance.Drive='" & strDrive & "'" & " And TargetInstance.Path='" & strPath & "'"
Dim colEvents:       Set colEvents = objWMIService. ExecNotificationQuery (strQuery)
Dim LastNew:         LastNew = Now
WScript.Echo "Monitoring new file creation... Press [Ctrl]-[C] to exit"
Do
    Set objEvent = colEvents.NextEvent()
    Set objTargetInst = objEvent.TargetInstance
    Select Case objEvent.Path_.Class
        Case "__InstanceCreationEvent"
            LastNew = Now
    End Select
    if DateDiff("n",LastNew,Now) >= intMinutes then 
        ' put whatever actions you want in here... the following two lines are for demo purposes only
        msgbox "The last new file was " & DateDiff("n",LastNew,Now) & " minute ago!",0,"No New Files"
        exit do
    end if
Loop
WScript中执行此命令,使其不可见,或CScript显示控制台窗口

替换IF块中的代码以执行需要执行的操作(将问题通知您)